ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
CachedObjectStorageFactory.php
Go to the documentation of this file.
1<?php
2
38{
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';
50
51
57 private static $_cacheStorageMethod = NULL;
58
64 private static $_cacheStorageClass = NULL;
65
66
72 private static $_storageMethods = array(
73 self::cache_in_memory,
74 self::cache_in_memory_gzip,
75 self::cache_in_memory_serialized,
76 self::cache_igbinary,
77 self::cache_to_phpTemp,
78 self::cache_to_discISAM,
79 self::cache_to_apc,
80 self::cache_to_memcache,
81 self::cache_to_wincache,
82 self::cache_to_sqlite,
83 self::cache_to_sqlite3,
84 );
85
86
92 private static $_storageMethodDefaultParameters = array(
93 self::cache_in_memory => array(
94 ),
95 self::cache_in_memory_gzip => array(
96 ),
97 self::cache_in_memory_serialized => array(
98 ),
99 self::cache_igbinary => array(
100 ),
101 self::cache_to_phpTemp => array( 'memoryCacheSize' => '1MB'
102 ),
103 self::cache_to_discISAM => array( 'dir' => NULL
104 ),
105 self::cache_to_apc => array( 'cacheTime' => 600
106 ),
107 self::cache_to_memcache => array( 'memcacheServer' => 'localhost',
108 'memcachePort' => 11211,
109 'cacheTime' => 600
110 ),
111 self::cache_to_wincache => array( 'cacheTime' => 600
112 ),
113 self::cache_to_sqlite => array(
114 ),
115 self::cache_to_sqlite3 => array(
116 ),
117 );
118
119
125 private static $_storageMethodParameters = array();
126
127
133 public static function getCacheStorageMethod()
134 {
136 } // function getCacheStorageMethod()
137
138
144 public static function getCacheStorageClass()
145 {
147 } // function getCacheStorageClass()
148
149
155 public static function getAllCacheStorageMethods()
156 {
158 } // function getCacheStorageMethods()
159
160
166 public static function getCacheStorageMethods()
167 {
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;
173 }
174 }
175 return $activeMethods;
176 } // function getCacheStorageMethods()
177
178
187 public static function initialize($method = self::cache_in_memory, $arguments = array())
188 {
189 if (!in_array($method,self::$_storageMethods)) {
190 return FALSE;
191 }
192
193 $cacheStorageClass = 'PHPExcel_CachedObjectStorage_'.$method;
194 if (!call_user_func(array( $cacheStorageClass,
195 'cacheMethodIsAvailable'))) {
196 return FALSE;
197 }
198
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;
203 }
204 }
205
206 if (self::$_cacheStorageMethod === NULL) {
207 self::$_cacheStorageClass = 'PHPExcel_CachedObjectStorage_' . $method;
208 self::$_cacheStorageMethod = $method;
209 }
210 return TRUE;
211 } // function initialize()
212
213
220 public static function getInstance(PHPExcel_Worksheet $parent)
221 {
222 $cacheMethodIsAvailable = TRUE;
223 if (self::$_cacheStorageMethod === NULL) {
224 $cacheMethodIsAvailable = self::initialize();
225 }
226
227 if ($cacheMethodIsAvailable) {
228 $instance = new self::$_cacheStorageClass( $parent,
229 self::$_storageMethodParameters[self::$_cacheStorageMethod]
230 );
231 if ($instance !== NULL) {
232 return $instance;
233 }
234 }
235
236 return FALSE;
237 } // function getInstance()
238
239
244 public static function finalize()
245 {
246 self::$_cacheStorageMethod = NULL;
247 self::$_cacheStorageClass = NULL;
248 self::$_storageMethodParameters = array();
249 }
250
251}
An exception for terminatinating execution or to throw for unit testing.
static getInstance(PHPExcel_Worksheet $parent)
Initialise the cache storage.
static getCacheStorageClass()
Return the current cache storage class.
static getCacheStorageMethods()
Return the list of all available cache storage methods.
static getCacheStorageMethod()
Return the current cache storage method.
static initialize($method=self::cache_in_memory, $arguments=array())
Identify the cache storage method to use.
static finalize()
Clear the cache storage.
static getAllCacheStorageMethods()
Return the list of all possible cache storage methods.