Added a cacheMethodIsAvailable() method to all cell cache classes, making it easier to identify if all the necessary classes/functions are available for each caching option.

Renamed the factory getCacheStorageMethods() method to getAllCacheStorageMethods(), returning all cache options in the library.
Wrote a new factory getCacheStorageMethods() method to return an array of those cache methods that are available with the current build of PHP (extensions tested, etc).
Refactored factory initialize() method to use the cacheMethodIsAvailable(), so factoring the logic for testing methods out of the factory.

git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@83741 2327b42d-5241-43d6-9e2a-de5ac946f064
This commit is contained in:
Mark Baker
2011-12-09 12:10:46 +00:00
parent 93e8a05780
commit cd7f0a1c51
9 changed files with 127 additions and 35 deletions
+16 -35
View File
@@ -81,50 +81,31 @@ class PHPExcel_CachedObjectStorageFactory {
} // function getCacheStorageClass()
public static function getCacheStorageMethods() {
public static function getAllCacheStorageMethods() {
return self::$_storageMethods;
} // function getCacheStorageMethods()
public static function getCacheStorageMethods() {
$activeMethods = array();
foreach(self::$_storageMethods as $storageMethod) {
$cacheStorageClass = 'PHPExcel_CachedObjectStorage_'.$storageMethod;
if (call_user_func(array($cacheStorageClass,'cacheMethodIsAvailable'))) {
$activeMethods[] = $storageMethod;
}
}
return $activeMethods;
} // function getCacheStorageMethods()
public static function initialize($method = self::cache_in_memory, $arguments = array()) {
if (!in_array($method,self::$_storageMethods)) {
return false;
}
switch($method) {
case self::cache_to_apc :
if (!function_exists('apc_store')) {
return false;
}
if (apc_sma_info() === false) {
return false;
}
break;
case self::cache_to_memcache :
if (!function_exists('memcache_add')) {
return false;
}
break;
case self::cache_to_wincache :
if (!function_exists('wincache_ucache_add')) {
return false;
}
break;
case self::cache_to_sqlite :
if (!function_exists('sqlite_open')) {
return false;
}
break;
case self::cache_to_sqlite3 :
if (!class_exists('SQLite3')) {
return false;
}
break;
case self::cache_igbinary :
if (!function_exists('igbinary_serialize')) {
return false;
}
break;
$cacheStorageClass = 'PHPExcel_CachedObjectStorage_'.$method;
if (!call_user_func(array($cacheStorageClass,'cacheMethodIsAvailable'))) {
return false;
}
self::$_storageMethodParameters[$method] = self::$_storageMethodDefaultParameters[$method];