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

Source for file object.php

Documentation is available at object.php

  1. <?php
  2. /**
  3.  * File containing the ezcCacheStorageObject 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, scalar values
  30.  * (int, float, string, bool) and objects implementing ezcBaseExportable in
  31.  * files on your hard disk as PHP code. This makes
  32.  * the restoring of cache data extremly fast, since the stored data is simply
  33.  * included and parsed by the PHP interpreter. It takes its base methods from
  34.  * the extended storage base class {@link ezcCacheStorageFile}.
  35.  *
  36.  * This cache storage deprecates {@link ezcCacheStorageFileArray}, since it is
  37.  * also capable of storing exportable objects in addition to arrays and scalar
  38.  * values.
  39.  *
  40.  * For example code of using a cache storage, see {@link ezcCacheManager}.
  41.  *
  42.  * The Cache package contains several other implementations of
  43.  * {@link ezcCacheStorageFile}. As there are:
  44.  *
  45.  * - ezcCacheStorageFileEvalArray
  46.  * - ezcCacheStorageFilePlain
  47.  *
  48.  * Both of these use different methods for actually storing the data, which are
  49.  * basically not superior to the implementation in this class.
  50.  * 
  51.  * @package Cache
  52.  * @version //autogentag//
  53.  */
  54. {
  55.     /**
  56.      * Fetch data from the cache.
  57.      *
  58.      * This method fetches the desired data from the file with $filename from
  59.      * disk. This implementation uses an include statement for fetching. The
  60.      * return value depends on the stored data and might either be an object
  61.      * implementing {@link ezcBaseExportable}, an array or a scalar value.
  62.      * 
  63.      * @param string $filename 
  64.      * @return mixed 
  65.      */
  66.     protected function fetchData$filename )
  67.     {
  68.         return include $filename );
  69.     }
  70.  
  71.     /**
  72.      * Serialize the data for storing.
  73.      *
  74.      * Serializes the given $data to a executable PHP code representation
  75.      * string. This works with objects implementing {@link ezcBaseExportable},
  76.      * arrays and scalar values (int, bool, float, string). The return value is
  77.      * executable PHP code to be stored to disk. The data can be unserialized
  78.      * using the {@link fetchData()} method.
  79.      * 
  80.      * @param mixed $data 
  81.      * @return string 
  82.      *
  83.      * @throws ezcCacheInvalidDataException
  84.      *          if the $data can not be serialized (e.g. an object that does not
  85.      *          implement ezcBaseExportable, a resource, ...).
  86.      */
  87.     protected function prepareData$data )
  88.     {
  89.         if ( ( is_object$data && !$data instanceof ezcBaseExportable ) )
  90.              || is_resource$data ) )
  91.         {
  92.             throw new ezcCacheInvalidDataExceptiongettype$data )array'simple''array''ezcBaseExportable' ) );
  93.         }
  94.         return "<?php\nreturn " var_export$datatrue ";\n?>\n";
  95.     }
  96. }
  97. ?>
Documentation generated by phpDocumentor 1.4.3