Apache Zeta Components Manual :: File Source for eval_array.php

Source for file eval_array.php

Documentation is available at eval_array.php

  1. <?php
  2. /**
  3.  * File containing the ezcCacheStorageEvalarray class.
  4.  *
  5.  * Licensed to the Apache Software Foundation (ASF) under one
  6.  * or more contributor license agreements.  See the NOTICE file
  7.  * distributed with this work for additional information
  8.  * regarding copyright ownership.  The ASF licenses this file
  9.  * to you under the Apache License, Version 2.0 (the
  10.  * "License"); you may not use this file except in compliance
  11.  * with the License.  You may obtain a copy of the License at
  12.  * 
  13.  *   http://www.apache.org/licenses/LICENSE-2.0
  14.  * 
  15.  * Unless required by applicable law or agreed to in writing,
  16.  * software distributed under the License is distributed on an
  17.  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18.  * KIND, either express or implied.  See the License for the
  19.  * specific language governing permissions and limitations
  20.  * under the License.
  21.  *
  22.  * @package Cache
  23.  * @version //autogentag//
  24.  * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  25.  * @filesource
  26.  */
  27.  
  28. /**
  29.  * This cache storage implementation stores arrays and scalar values (int,
  30.  * float, string, bool) in files on your hard disk as PHP code. In contrast to
  31.  * its sibling class {@link ezcCacheStorageFileArray}, the stored PHP code is
  32.  * not simply required to restore the cache data, but is evaluated using PHP's
  33.  * eval() function.  It takes its base methods from the extended storage base
  34.  * class {@link ezcCacheStorageFile}.
  35.  *
  36.  * Main purpose behind these 2 similar implementations is the following:
  37.  * Most byte code caches are capable of caching code for included files,
  38.  * but not for eval()'ed strings. Therefore the
  39.  * {@link ezcCacheStorageFileEvalarray} class will permit you to get your cached
  40.  * data not cached a second time by an accellerator like APC, whereas the
  41.  * {@link ezcCacheStorageFileArray} class will permit you to explicitly allow
  42.  * this. ATTENTION: If you do not use a byte code cache with your PHP
  43.  * installation, the use of {@link ezcCacheStorageFileArray} is recommended over
  44.  * the usage of {@link ezcCacheStorageEvalarray}, since eval() is much slower
  45.  * than directly requiring the stored PHP code.
  46.  *
  47.  * For example code of using a cache storage, see {@link ezcCacheManager}.
  48.  *
  49.  * The Cache package contains several other implementations of
  50.  * {@link ezcCacheStorageFile}. As there are:
  51.  *
  52.  * - ezcCacheStorageFileArray
  53.  * - ezcCacheStorageFilePlain
  54.  * 
  55.  * @package Cache
  56.  * @version //autogentag//
  57.  */
  58. {
  59.     /**
  60.      * Fetch data from a given file name.
  61.      *
  62.      * @see ezcCacheStorageFile::restore()
  63.      * 
  64.      * @param string $filename The file to fetch data from.
  65.      * @return mixed The data read from the file.
  66.      */
  67.     protected function fetchData$filename )
  68.     {
  69.         return evalfile_get_contents$filename ) );
  70.     }
  71.      
  72.     /**
  73.      * Serialize the data for storing.
  74.      * Serializes a PHP variable (except type resource and object) to a
  75.      * executable PHP code representation string.
  76.      * 
  77.      * @param mixed $data Simple type or array to serialize.
  78.      * @return string The serialized data
  79.      *
  80.      * @throws ezcCacheInvalidDataException
  81.      *          If the data submitted is an object or a resource, since this
  82.      *          implementation of {@link ezcCacheStorageFile} can only deal with
  83.      *          scalar and array values.
  84.      */
  85.     protected function prepareData$data )
  86.     {
  87.         if is_object$data || is_resource$data ) ) 
  88.         {
  89.             throw new ezcCacheInvalidDataExceptiongettype$data )array'simple''array' ) );
  90.         }
  91.         return "return " var_export$datatrue ";\n?>\n";
  92.     }
  93. }
  94. ?>
Documentation generated by phpDocumentor 1.4.3