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

Source for file array.php

Documentation is available at array.php

  1. <?php
  2. /**
  3.  * File containing the ezcCacheStorageArray 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
  30.  * (int, float, string, bool) in files on your hard disk as PHP code. This makes
  31.  * the restoring of cache data extremly fast, since the stored data is simply
  32.  * included and parsed by the PHP interpreter. It takes its base methods from
  33.  * the extended storage base class {@link ezcCacheStorageFile}.
  34.  *
  35.  * Another storage class with a similar approach exists,
  36.  * {@link ezcCacheStorageFileEvalArray}. This class is uses exactly the same
  37.  * mechanisms as ezcCacheStorageFileArray, except that is does not simply
  38.  * require the stored source code, but uses eval() to restore the data.
  39.  *
  40.  * Main purpose behind these 2 similar implementations is the following:
  41.  * Most byte code caches are capable of caching code for included files,
  42.  * but not for eval()ed strings. Therefore the *Evalarray class will
  43.  * permit you to get your cached data not cached a second time by an
  44.  * accellerator like APC, whereas the *Array class will permit you to
  45.  * explicitly allow this. ATTENTION: If you do not use a byte code cache
  46.  * with your PHP installation, the use of ezcCacheStorageFileArray is
  47.  * recommende over the usage of ezcCacheStorageEvalarray.
  48.  *
  49.  * For example code of using a cache storage, see {@link ezcCacheManager}.
  50.  *
  51.  * The Cache package contains several other implementations of
  52.  * {@link ezcCacheStorageFile}. As there are:
  53.  *
  54.  * - ezcCacheStorageFileEvalArray
  55.  * - ezcCacheStorageFilePlain
  56.  * 
  57.  * @package Cache
  58.  * @version //autogentag//
  59.  */
  60. {
  61.     /**
  62.      * Fetch data from the cache.
  63.      * This method does the fetching of the data itself. In this case, the
  64.      * method simply includes the file and returns the value returned by the
  65.      * include (or false on failure).
  66.      * 
  67.      * @param string $filename The file to fetch data from.
  68.      * @return mixed The fetched data or false on failure.
  69.      */
  70.     protected function fetchData$filename )
  71.     {
  72.         return include $filename );
  73.     }
  74.  
  75.     /**
  76.      * Serialize the data for storing.
  77.      * Serializes a PHP variable (except type resource and object) to a
  78.      * executable PHP code representation string.
  79.      * 
  80.      * @param mixed $data Simple type or array
  81.      * @return string The serialized data
  82.      *
  83.      * @throws ezcCacheInvalidDataException
  84.      *          If the data submitted is an object or a resource, since this
  85.      *          implementation of {@link ezcCacheStorageFile} can only deal with
  86.      *          scalar and array values.
  87.      */
  88.     protected function prepareData$data )
  89.     {
  90.         if is_object$data || is_resource$data ) ) 
  91.         {
  92.             throw new ezcCacheInvalidDataExceptiongettype$data )array'simple''array' ) );
  93.         }
  94.         return "<?php\nreturn " var_export$datatrue ";\n?>\n";
  95.     }
  96. }
  97. ?>
Documentation generated by phpDocumentor 1.4.3