6
* Copyright (c) 2006 - 2013 PHPExcel
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.
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.
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
23
* @package PHPExcel_CachedObjectStorage
24
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
25
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
26
* @version 1.7.9, 2013-06-02
31
* PHPExcel_CachedObjectStorageFactory
34
* @package PHPExcel_CachedObjectStorage
35
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
37
class PHPExcel_CachedObjectStorageFactory
39
const cache_in_memory = 'Memory';
40
const cache_in_memory_gzip = 'MemoryGZip';
41
const cache_in_memory_serialized = 'MemorySerialized';
42
const cache_igbinary = 'Igbinary';
43
const cache_to_discISAM = 'DiscISAM';
44
const cache_to_apc = 'APC';
45
const cache_to_memcache = 'Memcache';
46
const cache_to_phpTemp = 'PHPTemp';
47
const cache_to_wincache = 'Wincache';
48
const cache_to_sqlite = 'SQLite';
49
const cache_to_sqlite3 = 'SQLite3';
53
* Name of the method used for cell cacheing
57
private static $_cacheStorageMethod = NULL;
60
* Name of the class used for cell cacheing
64
private static $_cacheStorageClass = NULL;
68
* List of all possible cache storage methods
72
private static $_storageMethods = array(
73
self::cache_in_memory,
74
self::cache_in_memory_gzip,
75
self::cache_in_memory_serialized,
77
self::cache_to_phpTemp,
78
self::cache_to_discISAM,
80
self::cache_to_memcache,
81
self::cache_to_wincache,
82
self::cache_to_sqlite,
83
self::cache_to_sqlite3,
88
* Default arguments for each cache storage method
90
* @var array of mixed array
92
private static $_storageMethodDefaultParameters = array(
93
self::cache_in_memory => array(
95
self::cache_in_memory_gzip => array(
97
self::cache_in_memory_serialized => array(
99
self::cache_igbinary => array(
101
self::cache_to_phpTemp => array( 'memoryCacheSize' => '1MB'
103
self::cache_to_discISAM => array( 'dir' => NULL
105
self::cache_to_apc => array( 'cacheTime' => 600
107
self::cache_to_memcache => array( 'memcacheServer' => 'localhost',
108
'memcachePort' => 11211,
111
self::cache_to_wincache => array( 'cacheTime' => 600
113
self::cache_to_sqlite => array(
115
self::cache_to_sqlite3 => array(
121
* Arguments for the active cache storage method
123
* @var array of mixed array
125
private static $_storageMethodParameters = array();
129
* Return the current cache storage method
131
* @return string|NULL
133
public static function getCacheStorageMethod()
135
return self::$_cacheStorageMethod;
136
} // function getCacheStorageMethod()
140
* Return the current cache storage class
142
* @return PHPExcel_CachedObjectStorage_ICache|NULL
144
public static function getCacheStorageClass()
146
return self::$_cacheStorageClass;
147
} // function getCacheStorageClass()
151
* Return the list of all possible cache storage methods
155
public static function getAllCacheStorageMethods()
157
return self::$_storageMethods;
158
} // function getCacheStorageMethods()
162
* Return the list of all available cache storage methods
166
public static function getCacheStorageMethods()
168
$activeMethods = array();
169
foreach(self::$_storageMethods as $storageMethod) {
170
$cacheStorageClass = 'PHPExcel_CachedObjectStorage_' . $storageMethod;
171
if (call_user_func(array($cacheStorageClass, 'cacheMethodIsAvailable'))) {
172
$activeMethods[] = $storageMethod;
175
return $activeMethods;
176
} // function getCacheStorageMethods()
180
* Identify the cache storage method to use
182
* @param string $method Name of the method to use for cell cacheing
183
* @param array of mixed $arguments Additional arguments to pass to the cell caching class
187
public static function initialize($method = self::cache_in_memory, $arguments = array())
189
if (!in_array($method,self::$_storageMethods)) {
193
$cacheStorageClass = 'PHPExcel_CachedObjectStorage_'.$method;
194
if (!call_user_func(array( $cacheStorageClass,
195
'cacheMethodIsAvailable'))) {
199
self::$_storageMethodParameters[$method] = self::$_storageMethodDefaultParameters[$method];
200
foreach($arguments as $k => $v) {
201
if (array_key_exists($k, self::$_storageMethodParameters[$method])) {
202
self::$_storageMethodParameters[$method][$k] = $v;
206
if (self::$_cacheStorageMethod === NULL) {
207
self::$_cacheStorageClass = 'PHPExcel_CachedObjectStorage_' . $method;
208
self::$_cacheStorageMethod = $method;
211
} // function initialize()
215
* Initialise the cache storage
217
* @param PHPExcel_Worksheet $parent Enable cell caching for this worksheet
218
* @return PHPExcel_CachedObjectStorage_ICache
220
public static function getInstance(PHPExcel_Worksheet $parent)
222
$cacheMethodIsAvailable = TRUE;
223
if (self::$_cacheStorageMethod === NULL) {
224
$cacheMethodIsAvailable = self::initialize();
227
if ($cacheMethodIsAvailable) {
228
$instance = new self::$_cacheStorageClass( $parent,
229
self::$_storageMethodParameters[self::$_cacheStorageMethod]
231
if ($instance !== NULL) {
237
} // function getInstance()
241
* Clear the cache storage
244
public static function finalize()
246
self::$_cacheStorageMethod = NULL;
247
self::$_cacheStorageClass = NULL;
248
self::$_storageMethodParameters = array();