From cd7f0a1c519fcb1bc70cf263cc41dc29a286068a Mon Sep 17 00:00:00 2001 From: Mark Baker Date: Fri, 9 Dec 2011 12:10:46 +0000 Subject: [PATCH] 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 --- Classes/PHPExcel/CachedObjectStorage/APC.php | 18 +++++++ .../CachedObjectStorage/CacheBase.php | 11 ++++ .../PHPExcel/CachedObjectStorage/ICache.php | 8 +++ .../PHPExcel/CachedObjectStorage/Igbinary.php | 15 ++++++ .../PHPExcel/CachedObjectStorage/Memcache.php | 14 +++++ .../PHPExcel/CachedObjectStorage/SQLite.php | 15 ++++++ .../PHPExcel/CachedObjectStorage/SQLite3.php | 15 ++++++ .../PHPExcel/CachedObjectStorage/Wincache.php | 15 ++++++ .../PHPExcel/CachedObjectStorageFactory.php | 51 ++++++------------- 9 files changed, 127 insertions(+), 35 deletions(-) diff --git a/Classes/PHPExcel/CachedObjectStorage/APC.php b/Classes/PHPExcel/CachedObjectStorage/APC.php index 56ae7f8..ef550dc 100644 --- a/Classes/PHPExcel/CachedObjectStorage/APC.php +++ b/Classes/PHPExcel/CachedObjectStorage/APC.php @@ -219,4 +219,22 @@ class PHPExcel_CachedObjectStorage_APC extends PHPExcel_CachedObjectStorage_Cach } } // function __destruct() + + /** + * Identify whether the caching method is currently available + * Some methods are dependent on the availability of certain extensions being enabled in the PHP build + * + * @return boolean + */ + public static function cacheMethodIsAvailable() { + if (!function_exists('apc_store')) { + return false; + } + if (apc_sma_info() === false) { + return false; + } + + return true; + } + } diff --git a/Classes/PHPExcel/CachedObjectStorage/CacheBase.php b/Classes/PHPExcel/CachedObjectStorage/CacheBase.php index 4dd06fd..43412a3 100644 --- a/Classes/PHPExcel/CachedObjectStorage/CacheBase.php +++ b/Classes/PHPExcel/CachedObjectStorage/CacheBase.php @@ -176,4 +176,15 @@ class PHPExcel_CachedObjectStorage_CacheBase { } } // function copyCellCollection() + + /** + * Identify whether the caching method is currently available + * Some methods are dependent on the availability of certain extensions being enabled in the PHP build + * + * @return boolean + */ + public static function cacheMethodIsAvailable() { + return true; + } + } diff --git a/Classes/PHPExcel/CachedObjectStorage/ICache.php b/Classes/PHPExcel/CachedObjectStorage/ICache.php index 1ac1497..a400afe 100644 --- a/Classes/PHPExcel/CachedObjectStorage/ICache.php +++ b/Classes/PHPExcel/CachedObjectStorage/ICache.php @@ -101,4 +101,12 @@ interface PHPExcel_CachedObjectStorage_ICache */ public function copyCellCollection(PHPExcel_Worksheet $parent); + /** + * Identify whether the caching method is currently available + * Some methods are dependent on the availability of certain extensions being enabled in the PHP build + * + * @return boolean + */ + public static function cacheMethodIsAvailable(); + } diff --git a/Classes/PHPExcel/CachedObjectStorage/Igbinary.php b/Classes/PHPExcel/CachedObjectStorage/Igbinary.php index 1c6ba31..63012b7 100644 --- a/Classes/PHPExcel/CachedObjectStorage/Igbinary.php +++ b/Classes/PHPExcel/CachedObjectStorage/Igbinary.php @@ -108,4 +108,19 @@ class PHPExcel_CachedObjectStorage_Igbinary extends PHPExcel_CachedObjectStorage $this->_parent = null; } // function unsetWorksheetCells() + + /** + * Identify whether the caching method is currently available + * Some methods are dependent on the availability of certain extensions being enabled in the PHP build + * + * @return boolean + */ + public static function cacheMethodIsAvailable() { + if (!function_exists('igbinary_serialize')) { + return false; + } + + return true; + } + } diff --git a/Classes/PHPExcel/CachedObjectStorage/Memcache.php b/Classes/PHPExcel/CachedObjectStorage/Memcache.php index 4a13410..a4780ee 100644 --- a/Classes/PHPExcel/CachedObjectStorage/Memcache.php +++ b/Classes/PHPExcel/CachedObjectStorage/Memcache.php @@ -237,4 +237,18 @@ class PHPExcel_CachedObjectStorage_Memcache extends PHPExcel_CachedObjectStorage } } // function __destruct() + /** + * Identify whether the caching method is currently available + * Some methods are dependent on the availability of certain extensions being enabled in the PHP build + * + * @return boolean + */ + public static function cacheMethodIsAvailable() { + if (!function_exists('memcache_add')) { + return false; + } + + return true; + } + } diff --git a/Classes/PHPExcel/CachedObjectStorage/SQLite.php b/Classes/PHPExcel/CachedObjectStorage/SQLite.php index ddbdb8e..5813714 100644 --- a/Classes/PHPExcel/CachedObjectStorage/SQLite.php +++ b/Classes/PHPExcel/CachedObjectStorage/SQLite.php @@ -220,4 +220,19 @@ class PHPExcel_CachedObjectStorage_SQLite extends PHPExcel_CachedObjectStorage_C $this->_DBHandle = null; } // function __destruct() + + /** + * Identify whether the caching method is currently available + * Some methods are dependent on the availability of certain extensions being enabled in the PHP build + * + * @return boolean + */ + public static function cacheMethodIsAvailable() { + if (!function_exists('sqlite_open')) { + return false; + } + + return true; + } + } diff --git a/Classes/PHPExcel/CachedObjectStorage/SQLite3.php b/Classes/PHPExcel/CachedObjectStorage/SQLite3.php index 00bf16a..541d097 100644 --- a/Classes/PHPExcel/CachedObjectStorage/SQLite3.php +++ b/Classes/PHPExcel/CachedObjectStorage/SQLite3.php @@ -227,4 +227,19 @@ class PHPExcel_CachedObjectStorage_SQLite3 extends PHPExcel_CachedObjectStorage_ $this->_DBHandle = null; } // function __destruct() + + /** + * Identify whether the caching method is currently available + * Some methods are dependent on the availability of certain extensions being enabled in the PHP build + * + * @return boolean + */ + public static function cacheMethodIsAvailable() { + if (!class_exists('SQLite3')) { + return false; + } + + return true; + } + } diff --git a/Classes/PHPExcel/CachedObjectStorage/Wincache.php b/Classes/PHPExcel/CachedObjectStorage/Wincache.php index 93ce954..4b40069 100644 --- a/Classes/PHPExcel/CachedObjectStorage/Wincache.php +++ b/Classes/PHPExcel/CachedObjectStorage/Wincache.php @@ -231,4 +231,19 @@ class PHPExcel_CachedObjectStorage_Wincache extends PHPExcel_CachedObjectStorage } } // function __destruct() + + /** + * Identify whether the caching method is currently available + * Some methods are dependent on the availability of certain extensions being enabled in the PHP build + * + * @return boolean + */ + public static function cacheMethodIsAvailable() { + if (!function_exists('wincache_ucache_add')) { + return false; + } + + return true; + } + } diff --git a/Classes/PHPExcel/CachedObjectStorageFactory.php b/Classes/PHPExcel/CachedObjectStorageFactory.php index b6f5399..849de05 100644 --- a/Classes/PHPExcel/CachedObjectStorageFactory.php +++ b/Classes/PHPExcel/CachedObjectStorageFactory.php @@ -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];