[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/phpexcel/PHPExcel/ -> CachedObjectStorageFactory.php (source)

   1  <?php
   2  
   3  /**
   4   * PHPExcel_CachedObjectStorageFactory
   5   *
   6   * Copyright (c) 2006 - 2015 PHPExcel
   7   *
   8   * This library is free software; you can redistribute it and/or
   9   * modify it under the terms of the GNU Lesser General Public
  10   * License as published by the Free Software Foundation; either
  11   * version 2.1 of the License, or (at your option) any later version.
  12   *
  13   * This library is distributed in the hope that it will be useful,
  14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16   * Lesser General Public License for more details.
  17   *
  18   * You should have received a copy of the GNU Lesser General Public
  19   * License along with this library; if not, write to the Free Software
  20   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  21   *
  22   * @category   PHPExcel
  23   * @package    PHPExcel_CachedObjectStorage
  24   * @copyright  Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
  25   * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
  26   * @version    ##VERSION##, ##DATE##
  27   */
  28  class PHPExcel_CachedObjectStorageFactory
  29  {
  30      const cache_in_memory               = 'Memory';
  31      const cache_in_memory_gzip          = 'MemoryGZip';
  32      const cache_in_memory_serialized    = 'MemorySerialized';
  33      const cache_igbinary                = 'Igbinary';
  34      const cache_to_discISAM             = 'DiscISAM';
  35      const cache_to_apc                  = 'APC';
  36      const cache_to_memcache             = 'Memcache';
  37      const cache_to_phpTemp              = 'PHPTemp';
  38      const cache_to_wincache             = 'Wincache';
  39      const cache_to_sqlite               = 'SQLite';
  40      const cache_to_sqlite3              = 'SQLite3';
  41  
  42      /**
  43       * Name of the method used for cell cacheing
  44       *
  45       * @var string
  46       */
  47      private static $cacheStorageMethod = null;
  48  
  49      /**
  50       * Name of the class used for cell cacheing
  51       *
  52       * @var string
  53       */
  54      private static $cacheStorageClass = null;
  55  
  56      /**
  57       * List of all possible cache storage methods
  58       *
  59       * @var string[]
  60       */
  61      private static $storageMethods = array(
  62          self::cache_in_memory,
  63          self::cache_in_memory_gzip,
  64          self::cache_in_memory_serialized,
  65          self::cache_igbinary,
  66          self::cache_to_phpTemp,
  67          self::cache_to_discISAM,
  68          self::cache_to_apc,
  69          self::cache_to_memcache,
  70          self::cache_to_wincache,
  71          self::cache_to_sqlite,
  72          self::cache_to_sqlite3,
  73      );
  74  
  75      /**
  76       * Default arguments for each cache storage method
  77       *
  78       * @var array of mixed array
  79       */
  80      private static $storageMethodDefaultParameters = array(
  81          self::cache_in_memory               => array(
  82                                                      ),
  83          self::cache_in_memory_gzip          => array(
  84                                                      ),
  85          self::cache_in_memory_serialized    => array(
  86                                                      ),
  87          self::cache_igbinary                => array(
  88                                                      ),
  89          self::cache_to_phpTemp              => array( 'memoryCacheSize' => '1MB'
  90                                                      ),
  91          self::cache_to_discISAM             => array( 'dir'             => null
  92                                                      ),
  93          self::cache_to_apc                  => array( 'cacheTime'       => 600
  94                                                      ),
  95          self::cache_to_memcache             => array( 'memcacheServer'  => 'localhost',
  96                                                        'memcachePort'    => 11211,
  97                                                        'cacheTime'       => 600
  98                                                      ),
  99          self::cache_to_wincache             => array( 'cacheTime'       => 600
 100                                                      ),
 101          self::cache_to_sqlite               => array(
 102                                                      ),
 103          self::cache_to_sqlite3              => array(
 104                                                      ),
 105      );
 106  
 107      /**
 108       * Arguments for the active cache storage method
 109       *
 110       * @var array of mixed array
 111       */
 112      private static $storageMethodParameters = array();
 113  
 114      /**
 115       * Return the current cache storage method
 116       *
 117       * @return string|null
 118       **/
 119      public static function getCacheStorageMethod()
 120      {
 121          return self::$cacheStorageMethod;
 122      }
 123  
 124      /**
 125       * Return the current cache storage class
 126       *
 127       * @return PHPExcel_CachedObjectStorage_ICache|null
 128       **/
 129      public static function getCacheStorageClass()
 130      {
 131          return self::$cacheStorageClass;
 132      }
 133  
 134      /**
 135       * Return the list of all possible cache storage methods
 136       *
 137       * @return string[]
 138       **/
 139      public static function getAllCacheStorageMethods()
 140      {
 141          return self::$storageMethods;
 142      }
 143  
 144      /**
 145       * Return the list of all available cache storage methods
 146       *
 147       * @return string[]
 148       **/
 149      public static function getCacheStorageMethods()
 150      {
 151          $activeMethods = array();
 152          foreach (self::$storageMethods as $storageMethod) {
 153              $cacheStorageClass = 'PHPExcel_CachedObjectStorage_' . $storageMethod;
 154              if (call_user_func(array($cacheStorageClass, 'cacheMethodIsAvailable'))) {
 155                  $activeMethods[] = $storageMethod;
 156              }
 157          }
 158          return $activeMethods;
 159      }
 160  
 161      /**
 162       * Identify the cache storage method to use
 163       *
 164       * @param    string            $method        Name of the method to use for cell cacheing
 165       * @param    array of mixed    $arguments    Additional arguments to pass to the cell caching class
 166       *                                        when instantiating
 167       * @return boolean
 168       **/
 169      public static function initialize($method = self::cache_in_memory, $arguments = array())
 170      {
 171          if (!in_array($method, self::$storageMethods)) {
 172              return false;
 173          }
 174  
 175          $cacheStorageClass = 'PHPExcel_CachedObjectStorage_'.$method;
 176          if (!call_user_func(array( $cacheStorageClass,
 177                                     'cacheMethodIsAvailable'))) {
 178              return false;
 179          }
 180  
 181          self::$storageMethodParameters[$method] = self::$storageMethodDefaultParameters[$method];
 182          foreach ($arguments as $k => $v) {
 183              if (array_key_exists($k, self::$storageMethodParameters[$method])) {
 184                  self::$storageMethodParameters[$method][$k] = $v;
 185              }
 186          }
 187  
 188          if (self::$cacheStorageMethod === null) {
 189              self::$cacheStorageClass = 'PHPExcel_CachedObjectStorage_' . $method;
 190              self::$cacheStorageMethod = $method;
 191          }
 192          return true;
 193      }
 194  
 195      /**
 196       * Initialise the cache storage
 197       *
 198       * @param    PHPExcel_Worksheet     $parent        Enable cell caching for this worksheet
 199       * @return    PHPExcel_CachedObjectStorage_ICache
 200       **/
 201      public static function getInstance(PHPExcel_Worksheet $parent)
 202      {
 203          $cacheMethodIsAvailable = true;
 204          if (self::$cacheStorageMethod === null) {
 205              $cacheMethodIsAvailable = self::initialize();
 206          }
 207  
 208          if ($cacheMethodIsAvailable) {
 209              $instance = new self::$cacheStorageClass(
 210                  $parent,
 211                  self::$storageMethodParameters[self::$cacheStorageMethod]
 212              );
 213              if ($instance !== null) {
 214                  return $instance;
 215              }
 216          }
 217  
 218          return false;
 219      }
 220  
 221      /**
 222       * Clear the cache storage
 223       *
 224       **/
 225      public static function finalize()
 226      {
 227          self::$cacheStorageMethod = null;
 228          self::$cacheStorageClass = null;
 229          self::$storageMethodParameters = array();
 230      }
 231  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1