diff --git a/composer.json b/composer.json index d164a23..584eb50 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,8 @@ }, "require": { "phpmailer/phpmailer": "^6.9", - "imaginaria/jevix": "^2.3" + "imaginaria/jevix": "^2.3", + "livestreet/dklabcache": "^1.0" }, "scripts": { "test": "./vendor/bin/behat -c application/tests/behat/behat.yml" diff --git a/composer.lock b/composer.lock index b3197c4..93b2fef 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7b4202ff1acf59fe93ec06c4a5490060", + "content-hash": "2bc38009dc393d1478d6907f017229e2", "packages": [ { "name": "imaginaria/jevix", @@ -69,6 +69,56 @@ }, "time": "2022-05-29T22:00:45+00:00" }, + { + "name": "livestreet/dklabcache", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/olezhikz/dklabcache.git", + "reference": "b12ed6b12166496a6e5a657c80638a35950d7f94" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/olezhikz/dklabcache/zipball/b12ed6b12166496a6e5a657c80638a35950d7f94", + "reference": "b12ed6b12166496a6e5a657c80638a35950d7f94", + "shasum": "" + }, + "type": "library", + "autoload": { + "classmap": [ + "Cache/Backend/", + "Zend/", + "Zend/Cache/", + "Zend/Cache/Backend/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "dk", + "role": "Author" + }, + { + "name": "Dmitry Stepanenko", + "role": "Maintainer" + } + ], + "description": "Dklabcache for composer", + "keywords": [ + "cache", + "caching", + "file-system", + "redis", + "system" + ], + "support": { + "source": "https://github.com/olezhikz/dklabcache/tree/1.0.1" + }, + "time": "2019-09-19T07:10:44+00:00" + }, { "name": "phpmailer/phpmailer", "version": "v6.9.1", diff --git a/framework/classes/modules/cache/Cache.class.php b/framework/classes/modules/cache/Cache.class.php index d3cd19b..b44af5d 100644 --- a/framework/classes/modules/cache/Cache.class.php +++ b/framework/classes/modules/cache/Cache.class.php @@ -19,10 +19,6 @@ * */ -require_once(Config::Get('path.framework.libs_vendor.server') . '/DklabCache/config.php'); -require_once(LS_DKCACHE_PATH . 'Zend/Cache.php'); -require_once(LS_DKCACHE_PATH . 'Cache/Backend/Profiler.php'); - /** * Модуль кеширования. * Для реализации кеширования используетс библиотека Zend_Cache с бэкэндами File, Memcache и XCache. @@ -489,4 +485,4 @@ class ModuleCache extends Module { return $this->aStats; } -} \ No newline at end of file +} diff --git a/framework/classes/modules/cache/entity/BackendFile.entity.class.php b/framework/classes/modules/cache/entity/BackendFile.entity.class.php index eec0fc1..0a231e7 100644 --- a/framework/classes/modules/cache/entity/BackendFile.entity.class.php +++ b/framework/classes/modules/cache/entity/BackendFile.entity.class.php @@ -73,7 +73,6 @@ class ModuleCache_EntityBackendFile extends ModuleCache_EntityBackend */ public function Init($aParams = array()) { - require_once(LS_DKCACHE_PATH . 'Zend/Cache/Backend/File.php'); $sDirCache = $this->GetCacheDir(); $oCahe = new Zend_Cache_Backend_File( array( @@ -143,4 +142,4 @@ class ModuleCache_EntityBackendFile extends ModuleCache_EntityBackend { return $this->oCacheBackend->clean($cMode, $aTags); } -} \ No newline at end of file +} diff --git a/framework/libs/vendor/DklabCache/.htaccess b/framework/libs/vendor/DklabCache/.htaccess deleted file mode 100644 index 2859d7f..0000000 --- a/framework/libs/vendor/DklabCache/.htaccess +++ /dev/null @@ -1,2 +0,0 @@ -Order Deny,Allow -Deny from all \ No newline at end of file diff --git a/framework/libs/vendor/DklabCache/Cache/Backend/MemcachedMultiload.php b/framework/libs/vendor/DklabCache/Cache/Backend/MemcachedMultiload.php deleted file mode 100644 index b0bbe1c..0000000 --- a/framework/libs/vendor/DklabCache/Cache/Backend/MemcachedMultiload.php +++ /dev/null @@ -1,95 +0,0 @@ -_handle = self::_getPrivateProp($this, "_memcache"); - } - - - /** - * Returns native handle. - * - * @return Memcache Native PHP memcache handle. - */ - protected function _getHandle() - { - return $this->_handle; - } - - - /** - * Loads an array of items from the memcached. - * Extends Zend_Cache_Backend_Memcached with support of multi-get feature. - * - * @param array $ids A list of IDs to be loaded. - * @param bool $doNotTestCacheValidity See parent method. - * @return array An array of values for each ID. - */ - public function multiLoad($ids, $doNotTestCacheValidity = false) - { - if (!is_array($ids)) { - Zend_Cache::throwException('multiLoad() expects parameter 1 to be array, ' . gettype($ids) . ' given'); - } - if ($doNotTestCacheValidity) { - $this->_log("Zend_Cache_Backend_Memcached::load() : \$doNotTestCacheValidity=true is unsupported by the Memcached backend"); - } - $tmp = $this->_getHandle()->get($ids); - if (!is_array($tmp)) { - $tmp=array($tmp); - } - foreach ($tmp as $k => $v) { - if (is_array($v)) { - $tmp[$k] = $v[0]; - } - } - return $tmp; - } - - - /** - * Reads a private or protected property from the object. - * Unfortunately we have to use this hack, because Zend_Cache_Backend_Memcached - * does not declare $_memcache handle as protected. - * - * In PHP private properties are named with \x00 in the name. - * - * @param object $obj Object to read a property from. - * @param string $name Name of a protected or private property. - * @return mixed Property value or exception if property is not found. - */ - private static function _getPrivateProp($obj, $name) - { - $arraized = (array)$obj; - foreach ($arraized as $k => $v) { - if (substr($k, -strlen($name)) === $name) { - return $v; - } - } - throw new Exception( - "Cannot find $name property in Zend_Cache_Backend_Memcached; properties are: " - . array_map('addslashes', array_keys($arraized)) - ); - } -} diff --git a/framework/libs/vendor/DklabCache/Cache/Backend/Profiler.php b/framework/libs/vendor/DklabCache/Cache/Backend/Profiler.php deleted file mode 100644 index 2b1a435..0000000 --- a/framework/libs/vendor/DklabCache/Cache/Backend/Profiler.php +++ /dev/null @@ -1,95 +0,0 @@ -_backend = $backend; - $this->_incrementor = $incrementor; - } - - - public function setDirectives($directives) - { - return $this->_backend->setDirectives($directives); - } - - - public function load($id, $doNotTestCacheValidity = false) - { - $t0 = microtime(true); - $result = $this->_backend->load($id, $doNotTestCacheValidity); - call_user_func($this->_incrementor, microtime(true) - $t0, __METHOD__, $id); - return $result; - } - - - public function multiLoad($ids, $doNotTestCacheValidity = false) - { - if (!is_array($ids)) { - Zend_Cache::throwException('multiLoad() expects parameter 1 to be array, ' . gettype($ids) . ' given'); - } - if (method_exists($this->_backend, 'multiLoad')) { - $t0 = microtime(true); - $result = $this->_backend->multiLoad($ids, $doNotTestCacheValidity); - call_user_func($this->_incrementor, microtime(true) - $t0, __METHOD__, $ids); - return $result; - } - // No multiLoad() method avalilable, so we have to emulate it to keep - // the interface consistent. - $result = array(); - foreach ($ids as $i => $id) { - $result[$id] = $this->load($id, $doNotTestCacheValidity); - } - return $result; - } - - - public function test($id) - { - $t0 = microtime(true); - $result = $this->_backend->test($id); - call_user_func($this->_incrementor, microtime(true) - $t0, __METHOD__, $id); - return $result; - } - - - public function save($data, $id, $tags = array(), $specificLifetime = false) - { - $t0 = microtime(true); - $result = $this->_backend->save($data, $id, $tags, $specificLifetime); - call_user_func($this->_incrementor, microtime(true) - $t0, __METHOD__, $id); - return $result; - } - - - public function remove($id) - { - $t0 = microtime(true); - $result = $this->_backend->remove($id); - call_user_func($this->_incrementor, microtime(true) - $t0, __METHOD__, $id); - return $result; - } - - - public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array()) - { - $t0 = microtime(true); - $result = $this->_backend->clean($mode, $tags); - call_user_func($this->_incrementor, microtime(true) - $t0, __METHOD__, null); - return $result; - } -} diff --git a/framework/libs/vendor/DklabCache/Cache/Backend/TagEmuWrapper.php b/framework/libs/vendor/DklabCache/Cache/Backend/TagEmuWrapper.php deleted file mode 100644 index 542ec56..0000000 --- a/framework/libs/vendor/DklabCache/Cache/Backend/TagEmuWrapper.php +++ /dev/null @@ -1,213 +0,0 @@ -_backend = $backend; - } - - - public function setDirectives($directives) - { - return $this->_backend->setDirectives($directives); - } - - - public function load($id, $doNotTestCacheValidity = false) - { - return $this->_loadOrTestMulti($id, $doNotTestCacheValidity, false); - } - - - public function save($data, $id, $tags = array(), $specificLifetime = false) - { - // Save/update tags as usual infinite keys with value of tag version. - // If the tag already exists, do not rewrite it. - $tagsWithVersion = array(); - if (is_array($tags)) { - foreach ($tags as $tag) { - $mangledTag = $this->_mangleTag($tag); - $tagVersion = $this->_backend->load($mangledTag); - if ($tagVersion === false) { - $tagVersion = $this->_generateNewTagVersion(); - $this->_backend->save($tagVersion, $mangledTag, array(), null); - } - $tagsWithVersion[$tag] = $tagVersion; - } - } - // Data is saved in form of: array(tagsWithVersionArray, anyData). - $combined = array($tagsWithVersion, $data); - $serialized = serialize($combined); - return $this->_backend->save($serialized, $id, array(), $specificLifetime); - } - - - public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array()) - { - if ($mode == Zend_Cache::CLEANING_MODE_MATCHING_TAG) { - if (is_array($tags)) { - foreach ($tags as $tag) { - $this->_backend->remove($this->_mangleTag($tag)); - } - } - } else { - return $this->_backend->clean($mode, $tags); - } - } - - - public function test($id) - { - return $this->_loadOrTest($id, false, true); - } - - - public function remove($id) - { - return $this->_backend->remove($id); - } - - - /** - * Mangles the name to deny intersection of tag keys & data keys. - * Mangled tag names are NOT saved in memcache $combined[0] value, - * mangling is always performed on-demand (to same some space). - * - * @param string $tag Tag name to mangle. - * @return string Mangled tag name. - */ - private function _mangleTag($tag) - { - return __CLASS__ . "_" . self::VERSION . "_" . $tag; - } - - - /** - * The same as _mangleTag(), but mangles a list of tags. - * - * @see self::_mangleTag - * @param array $tags Tags to mangle. - * @return array List of mangled tags. - */ - private function _mangleTags($tags) - { - foreach ($tags as $i => $tag) { - $tags[$i] = $this->_mangleTag($tag); - } - return $tags; - } - - - /** - * Common method called from load() and test(). - * - * @param string $id - * @param bool $doNotTestCacheValidity - * @param bool $returnTrueIfValid If true, returns not the value contained - * in the slot, but "true". - * @return mixed - */ - private function _loadOrTest($id, $doNotTestCacheValidity = false, $returnTrueIfValid = false) - { - // Data is saved in form of: array(tagsWithVersionArray, anyData). - $serialized = $this->_backend->load($id, $doNotTestCacheValidity); - if ($serialized === false) { - return false; - } - $combined = unserialize($serialized); - if (!is_array($combined)) { - return false; - } - // Test if all tags has the same version as when the slot was created - // (i.e. still not removed and then recreated). - if (is_array($combined[0]) && $combined[0]) { - if (method_exists($this->_backend, 'multiLoad')) { - // If we have multiLoad(), optimize queries into one. - $allMangledTagValues = $this->_backend->multiLoad($this->_mangleTags(array_keys($combined[0]))); - foreach ($combined[0] as $tag => $savedTagVersion) { - $actualTagVersion = @$allMangledTagValues[$this->_mangleTag($tag)]; - if ($actualTagVersion !== $savedTagVersion) { - return false; - } - } - } else { - // Check all tags versions AND STOP IF WE FOUND AN INCONSISTENT ONE. - // Note that this optimization works fine only if $this->_backend is - // references to Dklab_Cache_Backend, but NOT via Dklab_Cache_Backend - // wrappers, because such wrappers emulate multiLoad() via multiple - // load() calls. - foreach ($combined[0] as $tag => $savedTagVersion) { - $actualTagVersion = $this->_backend->load($this->_mangleTag($tag)); - if ($actualTagVersion !== $savedTagVersion) { - return false; - } - } - } - } - return $returnTrueIfValid? true : $combined[1]; - } - - private function _loadOrTestMulti($id, $doNotTestCacheValidity = false, $returnTrueIfValid = false) - { - if (!is_array($id) or !method_exists($this->_backend, 'multiLoad')) { - return $this->_loadOrTest($id,$doNotTestCacheValidity,$returnTrueIfValid); - } - - $aDataMulti=$this->_backend->load($id, $doNotTestCacheValidity); - if ($aDataMulti === false) { - return false; - } - $aDataReturn=array(); - foreach ($aDataMulti as $sKey => $serialized) { - if ($serialized === false) { - continue; - } - $combined = unserialize($serialized); - if (!is_array($combined)) { - continue; - } - if (is_array($combined[0]) && $combined[0]) { - $allMangledTagValues = $this->_backend->multiLoad($this->_mangleTags(array_keys($combined[0]))); - foreach ($combined[0] as $tag => $savedTagVersion) { - $actualTagVersion = @$allMangledTagValues[$this->_mangleTag($tag)]; - if ($actualTagVersion !== $savedTagVersion) { - continue 2; - } - } - } - $aDataReturn[$sKey]=$returnTrueIfValid ? true : $combined[1]; - } - if (count($aDataReturn)>0) { - return $aDataReturn; - } - return false; - } - - /** - * Generates a new unique identifier for tag version. - * - * @return string Globally (hopefully) unique identifier. - */ - private function _generateNewTagVersion() - { - static $counter = 0; - $counter++; - return md5(microtime() . getmypid() . uniqid('') . $counter); - } -} diff --git a/framework/libs/vendor/DklabCache/Zend/Cache.php b/framework/libs/vendor/DklabCache/Zend/Cache.php deleted file mode 100644 index 4321739..0000000 --- a/framework/libs/vendor/DklabCache/Zend/Cache.php +++ /dev/null @@ -1,159 +0,0 @@ -setBackend($backendObject); - return $frontendObject; - - } - - /** - * Throw an exception - * - * Note : for perf reasons, the "load" of Zend/Cache/Exception is dynamic - * @param string $msg Message for the exception - * @throws Zend_Cache_Exception - */ - public static function throwException($msg) - { - // For perfs reasons, we use this dynamic inclusion - require_once LS_DKCACHE_PATH.'Zend/Cache/Exception.php'; - throw new Zend_Cache_Exception($msg); - } - - /** - * Normalize frontend and backend names to allow multiple words TitleCased - * - * @param string $name Name to normalize - * @return string - */ - protected static function _normalizeName($name) - { - $name = ucfirst(strtolower($name)); - $name = str_replace(array('-', '_', '.'), ' ', $name); - $name = ucwords($name); - $name = str_replace(' ', '', $name); - return $name; - } - -} diff --git a/framework/libs/vendor/DklabCache/Zend/Cache/Backend.php b/framework/libs/vendor/DklabCache/Zend/Cache/Backend.php deleted file mode 100644 index 0bb1d1d..0000000 --- a/framework/libs/vendor/DklabCache/Zend/Cache/Backend.php +++ /dev/null @@ -1,224 +0,0 @@ - (int) lifetime : - * - Cache lifetime (in seconds) - * - If null, the cache is valid forever - * - * =====> (int) logging : - * - if set to true, a logging is activated throw Zend_Log - * - * @var array directives - */ - protected $_directives = array( - 'lifetime' => 3600, - 'logging' => false, - 'logger' => null - ); - - /** - * Available options - * - * @var array available options - */ - protected $_options = array(); - - /** - * Constructor - * - * @param array $options Associative array of options - * @throws Zend_Cache_Exception - * @return void - */ - public function __construct($options = array()) - { - if (!is_array($options)) { - Zend_Cache::throwException('Options parameter must be an array'); - } - while (list($name, $value) = each($options)) { - $this->setOption($name, $value); - } - } - - /** - * Set the frontend directives - * - * @param array $directives Assoc of directives - * @throws Zend_Cache_Exception - * @return void - */ - public function setDirectives($directives) - { - if (!is_array($directives)) Zend_Cache::throwException('Directives parameter must be an array'); - while (list($name, $value) = each($directives)) { - if (!is_string($name)) { - Zend_Cache::throwException("Incorrect option name : $name"); - } - $name = strtolower($name); - if (array_key_exists($name, $this->_directives)) { - $this->_directives[$name] = $value; - } - - } - - $this->_loggerSanity(); - } - - /** - * Set an option - * - * @param string $name - * @param mixed $value - * @throws Zend_Cache_Exception - * @return void - */ - public function setOption($name, $value) - { - if (!is_string($name)) { - Zend_Cache::throwException("Incorrect option name : $name"); - } - $name = strtolower($name); - if (!array_key_exists($name, $this->_options)) { - Zend_Cache::throwException("Incorrect option name : $name"); - } - $this->_options[$name] = $value; - } - - /** - * Get the life time - * - * if $specificLifetime is not false, the given specific life time is used - * else, the global lifetime is used - * - * @param int $specificLifetime - * @return int Cache life time - */ - public function getLifetime($specificLifetime) - { - if ($specificLifetime === false) { - return $this->_directives['lifetime']; - } - return $specificLifetime; - } - - /** - * Return true if the automatic cleaning is available for the backend - * - * @return boolean - */ - public function isAutomaticCleaningAvailable() - { - return true; - } - - /** - * Return a system-wide tmp directory - * - * @return string System-wide tmp directory - */ - static function getTmpDir() - { - if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { - // windows... - foreach (array($_ENV, $_SERVER) as $tab) { - foreach (array('TEMP', 'TMP', 'windir', 'SystemRoot') as $key) { - if (isset($tab[$key])) { - $result = $tab[$key]; - if (($key == 'windir') or ($key == 'SystemRoot')) { - $result = $result . '\\temp'; - } - return $result; - } - } - } - return '\\temp'; - } else { - // unix... - if (isset($_ENV['TMPDIR'])) return $_ENV['TMPDIR']; - if (isset($_SERVER['TMPDIR'])) return $_SERVER['TMPDIR']; - return '/tmp'; - } - } - - /** - * Make sure if we enable logging that the Zend_Log class - * is available. - * Create a default log object if none is set. - * - * @throws Zend_Cache_Exception - * @return void - */ - protected function _loggerSanity() - { - if (!isset($this->_directives['logging']) || !$this->_directives['logging']) { - return; - } - try { - /** - * @see Zend_Loader - * @see Zend_Log - */ - require_once LS_DKCACHE_PATH.'Zend/Loader.php'; - Zend_Loader::loadClass('Zend_Log'); - } catch (Zend_Exception $e) { - Zend_Cache::throwException('Logging feature is enabled but the Zend_Log class is not available'); - } - if (isset($this->_directives['logger']) && $this->_directives['logger'] instanceof Zend_Log) { - return; - } - // Create a default logger to the standard output stream - Zend_Loader::loadClass('Zend_Log_Writer_Stream'); - $logger = new Zend_Log(new Zend_Log_Writer_Stream('php://output')); - $this->_directives['logger'] = $logger; - } - - /** - * Log a message at the WARN (4) priority. - * - * @param string $message - * @throws Zend_Cache_Exception - * @return void - */ - protected function _log($message, $priority = 4) - { - if (!$this->_directives['logging']) { - return; - } - if (!(isset($this->_directives['logger']) || $this->_directives['logger'] instanceof Zend_Log)) { - Zend_Cache::throwException('Logging is enabled but logger is not set'); - } - $logger = $this->_directives['logger']; - $logger->log($message, $priority); - } - -} diff --git a/framework/libs/vendor/DklabCache/Zend/Cache/Backend/File.php b/framework/libs/vendor/DklabCache/Zend/Cache/Backend/File.php deleted file mode 100644 index 2ff90fa..0000000 --- a/framework/libs/vendor/DklabCache/Zend/Cache/Backend/File.php +++ /dev/null @@ -1,716 +0,0 @@ - (string) cache_dir : - * - Directory where to put the cache files - * - * =====> (boolean) file_locking : - * - Enable / disable file_locking - * - Can avoid cache corruption under bad circumstances but it doesn't work on multithread - * webservers and on NFS filesystems for example - * - * =====> (boolean) read_control : - * - Enable / disable read control - * - If enabled, a control key is embeded in cache file and this key is compared with the one - * calculated after the reading. - * - * =====> (string) read_control_type : - * - Type of read control (only if read control is enabled). Available values are : - * 'md5' for a md5 hash control (best but slowest) - * 'crc32' for a crc32 hash control (lightly less safe but faster, better choice) - * 'adler32' for an adler32 hash control (excellent choice too, faster than crc32) - * 'strlen' for a length only test (fastest) - * - * =====> (int) hashed_directory_level : - * - Hashed directory level - * - Set the hashed directory structure level. 0 means "no hashed directory - * structure", 1 means "one level of directory", 2 means "two levels"... - * This option can speed up the cache only when you have many thousands of - * cache file. Only specific benchs can help you to choose the perfect value - * for you. Maybe, 1 or 2 is a good start. - * - * =====> (int) hashed_directory_umask : - * - Umask for hashed directory structure - * - * =====> (string) file_name_prefix : - * - prefix for cache files - * - be really carefull with this option because a too generic value in a system cache dir - * (like /tmp) can cause disasters when cleaning the cache - * - * =====> (int) cache_file_umask : - * - Umask for cache files - * - * =====> (int) metatadatas_array_max_size : - * - max size for the metadatas array (don't change this value unless you - * know what you are doing) - * - * @var array available options - */ - protected $_options = array( - 'cache_dir' => null, - 'file_locking' => true, - 'read_control' => true, - 'read_control_type' => 'crc32', - 'hashed_directory_level' => 0, - 'hashed_directory_umask' => 0700, - 'file_name_prefix' => 'zend_cache', - 'cache_file_umask' => 0600, - 'metadatas_array_max_size' => 100 - ); - - /** - * Array of metadatas (each item is an associative array) - * - * @var array - */ - private $_metadatasArray = array(); - - - /** - * Constructor - * - * @param array $options associative array of options - * @throws Zend_Cache_Exception - * @return void - */ - public function __construct(array $options = array()) - { - parent::__construct($options); - if (!is_null($this->_options['cache_dir'])) { // particular case for this option - $this->setCacheDir($this->_options['cache_dir']); - } else { - $this->setCacheDir(self::getTmpDir() . DIRECTORY_SEPARATOR, false); - } - if (isset($this->_options['file_name_prefix'])) { // particular case for this option - if (!preg_match('~^[\w]+$~', $this->_options['file_name_prefix'])) { - Zend_Cache::throwException('Invalid file_name_prefix : must use only [a-zA-A0-9_]'); - } - } - if ($this->_options['metadatas_array_max_size'] < 10) { - Zend_Cache::throwException('Invalid metadatas_array_max_size, must be > 10'); - } - } - - /** - * Set the cache_dir (particular case of setOption() method) - * - * @param string $value - * @param boolean $trailingSeparator If true, add a trailing separator is necessary - * @throws Zend_Cache_Exception - * @return void - */ - public function setCacheDir($value, $trailingSeparator = true) - { - if (!is_dir($value)) { - Zend_Cache::throwException('cache_dir must be a directory'); - } - if (!is_writable($value)) { - Zend_Cache::throwException('cache_dir is not writable'); - } - if ($trailingSeparator) { - // add a trailing DIRECTORY_SEPARATOR if necessary - $value = rtrim(realpath($value), '\\/') . DIRECTORY_SEPARATOR; - } - $this->_options['cache_dir'] = $value; - } - - /** - * Test if a cache is available for the given id and (if yes) return it (false else) - * - * @param string $id cache id - * @param boolean $doNotTestCacheValidity if set to true, the cache validity won't be tested - * @return string|false cached datas - */ - public function load($id, $doNotTestCacheValidity = false) - { - if (!($this->_test($id, $doNotTestCacheValidity))) { - // The cache is not hit ! - return false; - } - $metadatas = $this->_getMetadatas($id); - $file = $this->_file($id); - $data = $this->_fileGetContents($file); - if ($this->_options['read_control']) { - $hashData = $this->_hash($data, $this->_options['read_control_type']); - $hashControl = $metadatas['hash']; - if ($hashData != $hashControl) { - // Problem detected by the read control ! - $this->_log('Zend_Cache_Backend_File::load() / read_control : stored hash and computed hash do not match'); - $this->remove($id); - return false; - } - } - return $data; - } - - /** - * Test if a cache is available or not (for the given id) - * - * @param string $id cache id - * @return mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record - */ - public function test($id) - { - clearstatcache(); - return $this->_test($id, false); - } - - /** - * Save some string datas into a cache record - * - * Note : $data is always "string" (serialization is done by the - * core not by the backend) - * - * @param string $data Datas to cache - * @param string $id Cache id - * @param array $tags Array of strings, the cache record will be tagged by each string entry - * @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime) - * @return boolean true if no problem - */ - public function save($data, $id, $tags = array(), $specificLifetime = false) - { - clearstatcache(); - $file = $this->_file($id); - $path = $this->_path($id); - $firstTry = true; - $result = false; - if ($this->_options['hashed_directory_level'] > 0) { - if (!is_writable($path)) { - // maybe, we just have to build the directory structure - @mkdir($this->_path($id), $this->_options['hashed_directory_umask'], true); - @chmod($this->_path($id), $this->_options['hashed_directory_umask']); // see #ZF-320 (this line is required in some configurations) - } - if (!is_writable($path)) { - return false; - } - } - if ($this->_options['read_control']) { - $hash = $this->_hash($data, $this->_options['read_control_type']); - } else { - $hash = ''; - } - $metadatas = array( - 'hash' => $hash, - 'mtime' => time(), - 'expire' => $this->_expireTime($this->getLifetime($specificLifetime)), - 'tags' => $tags - ); - $res = $this->_setMetadatas($id, $metadatas); - if (!$res) { - // FIXME : log - return false; - } - $res = $this->_filePutContents($file, $data); - return $res; - } - - /** - * Remove a cache record - * - * @param string $id cache id - * @return boolean true if no problem - */ - public function remove($id) - { - $file = $this->_file($id); - return ($this->_delMetadatas($id) && $this->_remove($file)); - } - - /** - * Clean some cache records - * - * Available modes are : - * 'all' (default) => remove all cache entries ($tags is not used) - * 'old' => remove too old cache entries ($tags is not used) - * 'matchingTag' => remove cache entries matching all given tags - * ($tags can be an array of strings or a single string) - * 'notMatchingTag' => remove cache entries not matching one of the given tags - * ($tags can be an array of strings or a single string) - * - * @param string $mode clean mode - * @param tags array $tags array of tags - * @return boolean true if no problem - */ - public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array()) - { - // We use this private method to hide the recursive stuff - clearstatcache(); - return $this->_clean($this->_options['cache_dir'], $mode, $tags); - } - - /** - * PUBLIC METHOD FOR UNIT TESTING ONLY ! - * - * Force a cache record to expire - * - * @param string $id cache id - */ - public function ___expire($id) - { - $metadatas = $this->_getMetadatas($id); - if ($metadatas) { - $metadatas['expire'] = 1; - $this->_setMetadatas($id, $metadatas); - } - } - - /** - * Get a metadatas record - * - * @param string $id Cache id - * @return array|false Associative array of metadatas - */ - private function _getMetadatas($id) - { - if (isset($this->_metadatasArray[$id])) { - return $this->_metadatasArray[$id]; - } else { - $metadatas = $this->_loadMetadatas($id); - if (!$metadatas) { - return false; - } - $this->_setMetadatas($id, $metadatas, false); - return $metadatas; - } - } - - /** - * Set a metadatas record - * - * @param string $id Cache id - * @param array $metadatas Associative array of metadatas - * @param boolean $save optional pass false to disable saving to file - * @return boolean True if no problem - */ - private function _setMetadatas($id, $metadatas, $save = true) - { - if (count($this->_metadatasArray) >= $this->_options['metadatas_array_max_size']) { - $n = (int) ($this->_options['metadatas_array_max_size'] / 10); - $this->_metadatasArray = array_slice($this->_metadatasArray, $n); - } - if ($save) { - $result = $this->_saveMetadatas($id, $metadatas); - if (!$result) { - return false; - } - } - $this->_metadatasArray[$id] = $metadatas; - return true; - } - - /** - * Drop a metadata record - * - * @param string $id Cache id - * @return boolean True if no problem - */ - private function _delMetadatas($id) - { - if (isset($this->_metadatasArray[$id])) { - unset($this->_metadatasArray[$id]); - } - $file = $this->_metadatasFile($id); - return $this->_remove($file); - } - - /** - * Clear the metadatas array - * - * @return void - */ - private function _cleanMetadatas() - { - $this->_metadatasArray = array(); - } - - /** - * Load metadatas from disk - * - * @param string $id Cache id - * @return array|false Metadatas associative array - */ - private function _loadMetadatas($id) - { - $file = $this->_metadatasFile($id); - $result = $this->_fileGetContents($file); - if (!$result) { - return false; - } - $tmp = @unserialize($result); - return $tmp; - } - - /** - * Save metadatas to disk - * - * @param string $id Cache id - * @param array $metadatas Associative array - * @return boolean True if no problem - */ - private function _saveMetadatas($id, $metadatas) - { - $file = $this->_metadatasFile($id); - $result = $this->_filePutContents($file, serialize($metadatas)); - if (!$result) { - return false; - } - return true; - } - - /** - * Make and return a file name (with path) for metadatas - * - * @param string $id Cache id - * @return string Metadatas file name (with path) - */ - private function _metadatasFile($id) - { - $path = $this->_path($id); - $fileName = $this->_idToFileName('internal-metadatas---' . $id); - return $path . $fileName; - } - - /** - * Check if the given filename is a metadatas one - * - * @param string $fileName File name - * @return boolean True if it's a metadatas one - */ - private function _isMetadatasFile($fileName) - { - $id = $this->_fileNameToId($fileName); - if (substr($id, 0, 21) == 'internal-metadatas---') { - return true; - } else { - return false; - } - } - - /** - * Remove a file - * - * If we can't remove the file (because of locks or any problem), we will touch - * the file to invalidate it - * - * @param string $file Complete file path - * @return boolean True if ok - */ - private function _remove($file) - { - if (!is_file($file)) { - return false; - } - if (!@unlink($file)) { - # we can't remove the file (because of locks or any problem) - $this->_log("Zend_Cache_Backend_File::_remove() : we can't remove $file"); - return false; - } - return true; - } - - /** - * Clean some cache records (private method used for recursive stuff) - * - * Available modes are : - * Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used) - * Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used) - * Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags - * ($tags can be an array of strings or a single string) - * Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => remove cache entries not {matching one of the given tags} - * ($tags can be an array of strings or a single string) - * - * @param string $dir Directory to clean - * @param string $mode Clean mode - * @param array $tags Array of tags - * @throws Zend_Cache_Exception - * @return boolean True if no problem - */ - private function _clean($dir, $mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array()) - { - if (!is_dir($dir)) { - return false; - } - $result = true; - $prefix = $this->_options['file_name_prefix']; - $glob = @glob($dir . $prefix . '--*'); - if ($glob === false) { - return true; - } - foreach ($glob as $file) { - if (is_file($file)) { - $fileName = basename($file); - if ($this->_isMetadatasFile($fileName)) { - // in CLEANING_MODE_ALL, we drop anything, even remainings old metadatas files - if ($mode != Zend_Cache::CLEANING_MODE_ALL) { - continue; - } - } - $id = $this->_fileNameToId($fileName); - $metadatas = $this->_getMetadatas($id); - if ($metadatas === FALSE) { - $metadatas = array('expire' => 1, 'tags' => array()); - } - switch ($mode) { - case Zend_Cache::CLEANING_MODE_ALL: - $res = $this->remove($id); - if (!$res) { - // in this case only, we accept a problem with the metadatas file drop - $res = $this->_remove($file); - } - $result = $result && $res; - break; - case Zend_Cache::CLEANING_MODE_OLD: - if (time() > $metadatas['expire']) { - $result = ($result) && ($this->remove($id)); - } - break; - case Zend_Cache::CLEANING_MODE_MATCHING_TAG: - $matching = false; - foreach ($tags as $tag) { - if (in_array($tag, $metadatas['tags'])) { - $matching = true; - break; - } - } - if ($matching) { - $result = ($result) && ($this->remove($id)); - } - break; - case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG: - $matching = false; - foreach ($tags as $tag) { - if (in_array($tag, $metadatas['tags'])) { - $matching = true; - break; - } - } - if (!$matching) { - $result = ($result) && $this->remove($id); - } - break; - default: - Zend_Cache::throwException('Invalid mode for clean() method'); - break; - } - } - if ((is_dir($file)) and ($this->_options['hashed_directory_level']>0)) { - // Recursive call - $result = ($result) && ($this->_clean($file . DIRECTORY_SEPARATOR, $mode, $tags)); - if ($mode=='all') { - // if mode=='all', we try to drop the structure too - @rmdir($file); - } - } - } - return $result; - } - - /** - * Compute & return the expire time - * - * @return int expire time (unix timestamp) - */ - private function _expireTime($lifetime) - { - if (is_null($lifetime)) { - return 9999999999; - } - return time() + $lifetime; - } - - /** - * Make a control key with the string containing datas - * - * @param string $data Data - * @param string $controlType Type of control 'md5', 'crc32' or 'strlen' - * @throws Zend_Cache_Exception - * @return string Control key - */ - private function _hash($data, $controlType) - { - switch ($controlType) { - case 'md5': - return md5($data); - case 'crc32': - return crc32($data); - case 'strlen': - return strlen($data); - case 'adler32': - return hash('adler32', $data); - default: - Zend_Cache::throwException("Incorrect hash function : $controlType"); - } - } - - /** - * Transform a cache id into a file name and return it - * - * @param string $id Cache id - * @return string File name - */ - private function _idToFileName($id) - { - $prefix = $this->_options['file_name_prefix']; - $result = $prefix . '---' . $id; - return $result; - } - - /** - * Make and return a file name (with path) - * - * @param string $id Cache id - * @return string File name (with path) - */ - private function _file($id) - { - $path = $this->_path($id); - $fileName = $this->_idToFileName($id); - return $path . $fileName; - } - - /** - * Return the complete directory path of a filename (including hashedDirectoryStructure) - * - * @param string $id Cache id - * @return string Complete directory path - */ - private function _path($id) - { - $root = $this->_options['cache_dir']; - $prefix = $this->_options['file_name_prefix']; - if ($this->_options['hashed_directory_level']>0) { - $hash = hash('adler32', $id); - for ($i=0 ; $i < $this->_options['hashed_directory_level'] ; $i++) { - $root = $root . $prefix . '--' . substr($hash, 0, $i + 1) . DIRECTORY_SEPARATOR; - } - } - return $root; - } - - /** - * Test if the given cache id is available (and still valid as a cache record) - * - * @param string $id Cache id - * @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested - * @return boolean|mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record - */ - private function _test($id, $doNotTestCacheValidity) - { - $metadatas = $this->_getMetadatas($id); - if (!$metadatas) { - return false; - } - if ($doNotTestCacheValidity || (time() <= $metadatas['expire'])) { - return $metadatas['mtime']; - } - return false; - } - - /** - * Return the file content of the given file - * - * @param string $file File complete path - * @return string File content (or false if problem) - */ - private function _fileGetContents($file) - { - $result = false; - if (!is_file($file)) { - return false; - } - if (function_exists('get_magic_quotes_runtime') && function_exists('set_magic_quotes_runtime')) { - $mqr = @get_magic_quotes_runtime(); - @set_magic_quotes_runtime(0); - } - $f = @fopen($file, 'rb'); - if ($f) { - if ($this->_options['file_locking']) @flock($f, LOCK_SH); - $result = stream_get_contents($f); - if ($this->_options['file_locking']) @flock($f, LOCK_UN); - @fclose($f); - } - if (function_exists('set_magic_quotes_runtime')) { - @set_magic_quotes_runtime($mqr); - } - return $result; - } - - /** - * Put the given string into the given file - * - * @param string $file File complete path - * @param string $string String to put in file - * @return boolean true if no problem - */ - private function _filePutContents($file, $string) - { - $result = false; - $f = @fopen($file, 'ab+'); - if ($f) { - if ($this->_options['file_locking']) @flock($f, LOCK_EX); - fseek($f, 0); - ftruncate($f, 0); - $tmp = @fwrite($f, $string); - if (!($tmp === FALSE)) { - $result = true; - } - @fclose($f); - } - @chmod($file, $this->_options['cache_file_umask']); - return $result; - } - - /** - * Transform a file name into cache id and return it - * - * @param string $fileName File name - * @return string Cache id - */ - private function _fileNameToId($fileName) - { - $prefix = $this->_options['file_name_prefix']; - return preg_replace('~^' . $prefix . '---(.*)$~', '$1', $fileName); - } - -} diff --git a/framework/libs/vendor/DklabCache/Zend/Cache/Backend/Interface.php b/framework/libs/vendor/DklabCache/Zend/Cache/Backend/Interface.php deleted file mode 100644 index 75a0989..0000000 --- a/framework/libs/vendor/DklabCache/Zend/Cache/Backend/Interface.php +++ /dev/null @@ -1,96 +0,0 @@ - infinite lifetime) - * @return boolean true if no problem - */ - public function save($data, $id, $tags = array(), $specificLifetime = false); - - /** - * Remove a cache record - * - * @param string $id Cache id - * @return boolean True if no problem - */ - public function remove($id); - - /** - * Clean some cache records - * - * Available modes are : - * Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used) - * Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used) - * Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags - * ($tags can be an array of strings or a single string) - * Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => remove cache entries not {matching one of the given tags} - * ($tags can be an array of strings or a single string) - * - * @param string $mode Clean mode - * @param array $tags Array of tags - * @return boolean true if no problem - */ - public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array()); - -} diff --git a/framework/libs/vendor/DklabCache/Zend/Cache/Backend/Libmemcached.php b/framework/libs/vendor/DklabCache/Zend/Cache/Backend/Libmemcached.php deleted file mode 100644 index 3415317..0000000 --- a/framework/libs/vendor/DklabCache/Zend/Cache/Backend/Libmemcached.php +++ /dev/null @@ -1,484 +0,0 @@ - (array) servers : - * an array of memcached server ; each memcached server is described by an associative array : - * 'host' => (string) : the name of the memcached server - * 'port' => (int) : the port of the memcached server - * 'weight' => (int) : number of buckets to create for this server which in turn control its - * probability of it being selected. The probability is relative to the total - * weight of all servers. - * =====> (array) client : - * an array of memcached client options ; the memcached client is described by an associative array : - * @see http://php.net/manual/memcached.constants.php - * - The option name can be the name of the constant without the prefix 'OPT_' - * or the integer value of this option constant - * - * @var array available options - */ - protected $_options = array( - 'servers' => array(array( - 'host' => self::DEFAULT_HOST, - 'port' => self::DEFAULT_PORT, - 'weight' => self::DEFAULT_WEIGHT, - )), - 'client' => array() - ); - - /** - * Memcached object - * - * @var mixed memcached object - */ - protected $_memcache = null; - - /** - * Constructor - * - * @param array $options associative array of options - * @throws Zend_Cache_Exception - * @return void - */ - public function __construct(array $options = array()) - { - if (!extension_loaded('memcached')) { - Zend_Cache::throwException('The memcached extension must be loaded for using this backend !'); - } - - // override default client options - $this->_options['client'] = array( - Memcached::OPT_DISTRIBUTION => Memcached::DISTRIBUTION_CONSISTENT, - Memcached::OPT_HASH => Memcached::HASH_MD5, - Memcached::OPT_LIBKETAMA_COMPATIBLE => true, - ); - - parent::__construct($options); - - if (isset($this->_options['servers'])) { - $value = $this->_options['servers']; - if (isset($value['host'])) { - // in this case, $value seems to be a simple associative array (one server only) - $value = array(0 => $value); // let's transform it into a classical array of associative arrays - } - $this->setOption('servers', $value); - } - $this->_memcache = new Memcached; - - // setup memcached client options - foreach ($this->_options['client'] as $name => $value) { - $optId = null; - if (is_int($name)) { - $optId = $name; - } else { - $optConst = 'Memcached::OPT_' . strtoupper($name); - if (defined($optConst)) { - $optId = constant($optConst); - } else { - $this->_log("Unknown memcached client option '{$name}' ({$optConst})"); - } - } - if (null !== $optId) { - if (!$this->_memcache->setOption($optId, $value)) { - $this->_log("Setting memcached client option '{$optId}' failed"); - } - } - } - - // setup memcached servers - $servers = array(); - foreach ($this->_options['servers'] as $server) { - if (!array_key_exists('port', $server)) { - $server['port'] = self::DEFAULT_PORT; - } - if (!array_key_exists('weight', $server)) { - $server['weight'] = self::DEFAULT_WEIGHT; - } - - $servers[] = array($server['host'], $server['port'], $server['weight']); - } - $this->_memcache->addServers($servers); - } - - /** - * Test if a cache is available for the given id and (if yes) return it (false else) - * - * @param string $id Cache id - * @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested - * @return string|false cached datas - */ - public function load($id, $doNotTestCacheValidity = false) - { - $tmp = $this->_memcache->get($id); - if (isset($tmp[0])) { - return $tmp[0]; - } - return false; - } - - /** - * Test if a cache is available or not (for the given id) - * - * @param string $id Cache id - * @return int|false (a cache is not available) or "last modified" timestamp (int) of the available cache record - */ - public function test($id) - { - $tmp = $this->_memcache->get($id); - if (isset($tmp[0], $tmp[1])) { - return (int)$tmp[1]; - } - return false; - } - - /** - * Save some string datas into a cache record - * - * Note : $data is always "string" (serialization is done by the - * core not by the backend) - * - * @param string $data Datas to cache - * @param string $id Cache id - * @param array $tags Array of strings, the cache record will be tagged by each string entry - * @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime) - * @return boolean True if no problem - */ - public function save($data, $id, $tags = array(), $specificLifetime = false) - { - $lifetime = $this->getLifetime($specificLifetime); - - // ZF-8856: using set because add needs a second request if item already exists - $result = @$this->_memcache->set($id, array($data, time(), $lifetime), $lifetime); - if ($result === false) { - $rsCode = $this->_memcache->getResultCode(); - $rsMsg = $this->_memcache->getResultMessage(); - $this->_log("Memcached::set() failed: [{$rsCode}] {$rsMsg}"); - } - - if (count($tags) > 0) { - $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_LIBMEMCACHED_BACKEND); - } - - return $result; - } - - /** - * Remove a cache record - * - * @param string $id Cache id - * @return boolean True if no problem - */ - public function remove($id) - { - return $this->_memcache->delete($id); - } - - /** - * Clean some cache records - * - * Available modes are : - * 'all' (default) => remove all cache entries ($tags is not used) - * 'old' => unsupported - * 'matchingTag' => unsupported - * 'notMatchingTag' => unsupported - * 'matchingAnyTag' => unsupported - * - * @param string $mode Clean mode - * @param array $tags Array of tags - * @throws Zend_Cache_Exception - * @return boolean True if no problem - */ - public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array()) - { - switch ($mode) { - case Zend_Cache::CLEANING_MODE_ALL: - return $this->_memcache->flush(); - break; - case Zend_Cache::CLEANING_MODE_OLD: - $this->_log("Zend_Cache_Backend_Libmemcached::clean() : CLEANING_MODE_OLD is unsupported by the Libmemcached backend"); - break; - case Zend_Cache::CLEANING_MODE_MATCHING_TAG: - case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG: - case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG: - $this->_log(self::TAGS_UNSUPPORTED_BY_CLEAN_OF_LIBMEMCACHED_BACKEND); - break; - default: - Zend_Cache::throwException('Invalid mode for clean() method'); - break; - } - } - - /** - * Return true if the automatic cleaning is available for the backend - * - * @return boolean - */ - public function isAutomaticCleaningAvailable() - { - return false; - } - - /** - * Set the frontend directives - * - * @param array $directives Assoc of directives - * @throws Zend_Cache_Exception - * @return void - */ - public function setDirectives($directives) - { - parent::setDirectives($directives); - $lifetime = $this->getLifetime(false); - if ($lifetime > 2592000) { - // #ZF-3490 : For the memcached backend, there is a lifetime limit of 30 days (2592000 seconds) - $this->_log('memcached backend has a limit of 30 days (2592000 seconds) for the lifetime'); - } - if ($lifetime === null) { - // #ZF-4614 : we tranform null to zero to get the maximal lifetime - parent::setDirectives(array('lifetime' => 0)); - } - } - - /** - * Return an array of stored cache ids - * - * @return array array of stored cache ids (string) - */ - public function getIds() - { - $this->_log("Zend_Cache_Backend_Libmemcached::save() : getting the list of cache ids is unsupported by the Libmemcached backend"); - return array(); - } - - /** - * Return an array of stored tags - * - * @return array array of stored tags (string) - */ - public function getTags() - { - $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_LIBMEMCACHED_BACKEND); - return array(); - } - - /** - * Return an array of stored cache ids which match given tags - * - * In case of multiple tags, a logical AND is made between tags - * - * @param array $tags array of tags - * @return array array of matching cache ids (string) - */ - public function getIdsMatchingTags($tags = array()) - { - $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_LIBMEMCACHED_BACKEND); - return array(); - } - - /** - * Return an array of stored cache ids which don't match given tags - * - * In case of multiple tags, a logical OR is made between tags - * - * @param array $tags array of tags - * @return array array of not matching cache ids (string) - */ - public function getIdsNotMatchingTags($tags = array()) - { - $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_LIBMEMCACHED_BACKEND); - return array(); - } - - /** - * Return an array of stored cache ids which match any given tags - * - * In case of multiple tags, a logical AND is made between tags - * - * @param array $tags array of tags - * @return array array of any matching cache ids (string) - */ - public function getIdsMatchingAnyTags($tags = array()) - { - $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_LIBMEMCACHED_BACKEND); - return array(); - } - - /** - * Return the filling percentage of the backend storage - * - * @throws Zend_Cache_Exception - * @return int integer between 0 and 100 - */ - public function getFillingPercentage() - { - $mems = $this->_memcache->getStats(); - if ($mems === false) { - return 0; - } - - $memSize = null; - $memUsed = null; - foreach ($mems as $key => $mem) { - if ($mem === false) { - $this->_log('can\'t get stat from ' . $key); - continue; - } - - $eachSize = $mem['limit_maxbytes']; - $eachUsed = $mem['bytes']; - if ($eachUsed > $eachSize) { - $eachUsed = $eachSize; - } - - $memSize += $eachSize; - $memUsed += $eachUsed; - } - - if ($memSize === null || $memUsed === null) { - Zend_Cache::throwException('Can\'t get filling percentage'); - } - - return ((int) (100. * ($memUsed / $memSize))); - } - - /** - * Return an array of metadatas for the given cache id - * - * The array must include these keys : - * - expire : the expire timestamp - * - tags : a string array of tags - * - mtime : timestamp of last modification time - * - * @param string $id cache id - * @return array array of metadatas (false if the cache id is not found) - */ - public function getMetadatas($id) - { - $tmp = $this->_memcache->get($id); - if (isset($tmp[0], $tmp[1], $tmp[2])) { - $data = $tmp[0]; - $mtime = $tmp[1]; - $lifetime = $tmp[2]; - return array( - 'expire' => $mtime + $lifetime, - 'tags' => array(), - 'mtime' => $mtime - ); - } - - return false; - } - - /** - * Give (if possible) an extra lifetime to the given cache id - * - * @param string $id cache id - * @param int $extraLifetime - * @return boolean true if ok - */ - public function touch($id, $extraLifetime) - { - $tmp = $this->_memcache->get($id); - if (isset($tmp[0], $tmp[1], $tmp[2])) { - $data = $tmp[0]; - $mtime = $tmp[1]; - $lifetime = $tmp[2]; - $newLifetime = $lifetime - (time() - $mtime) + $extraLifetime; - if ($newLifetime <=0) { - return false; - } - // #ZF-5702 : we try replace() first becase set() seems to be slower - if (!($result = $this->_memcache->replace($id, array($data, time(), $newLifetime), $newLifetime))) { - $result = $this->_memcache->set($id, array($data, time(), $newLifetime), $newLifetime); - if ($result === false) { - $rsCode = $this->_memcache->getResultCode(); - $rsMsg = $this->_memcache->getResultMessage(); - $this->_log("Memcached::set() failed: [{$rsCode}] {$rsMsg}"); - } - } - return $result; - } - return false; - } - - /** - * Return an associative array of capabilities (booleans) of the backend - * - * The array must include these keys : - * - automatic_cleaning (is automating cleaning necessary) - * - tags (are tags supported) - * - expired_read (is it possible to read expired cache records - * (for doNotTestCacheValidity option for example)) - * - priority does the backend deal with priority when saving - * - infinite_lifetime (is infinite lifetime can work with this backend) - * - get_list (is it possible to get the list of cache ids and the complete list of tags) - * - * @return array associative of with capabilities - */ - public function getCapabilities() - { - return array( - 'automatic_cleaning' => false, - 'tags' => false, - 'expired_read' => false, - 'priority' => false, - 'infinite_lifetime' => false, - 'get_list' => false - ); - } - -} diff --git a/framework/libs/vendor/DklabCache/Zend/Cache/Backend/Memcached.php b/framework/libs/vendor/DklabCache/Zend/Cache/Backend/Memcached.php deleted file mode 100644 index ac99bbc..0000000 --- a/framework/libs/vendor/DklabCache/Zend/Cache/Backend/Memcached.php +++ /dev/null @@ -1,249 +0,0 @@ - (array) servers : - * an array of memcached server ; each memcached server is described by an associative array : - * 'host' => (string) : the name of the memcached server - * 'port' => (int) : the port of the memcached server - * 'persistent' => (bool) : use or not persistent connections to this memcached server - * - * =====> (boolean) compression : - * true if you want to use on-the-fly compression - * - * @var array available options - */ - protected $_options = array( - 'servers' => array(array( - 'host' => Zend_Cache_Backend_Memcached::DEFAULT_HOST, - 'port' => Zend_Cache_Backend_Memcached::DEFAULT_PORT, - 'persistent' => Zend_Cache_Backend_Memcached::DEFAULT_PERSISTENT - )), - 'compression' => false - ); - - /** - * Memcache object - * - * @var mixed memcache object - */ - private $_memcache = null; - - /** - * Constructor - * - * @param array $options associative array of options - * @throws Zend_Cache_Exception - * @return void - */ - public function __construct($options = array()) - { - if (!extension_loaded('memcache')) { - Zend_Cache::throwException('The memcache extension must be loaded for using this backend !'); - } - parent::__construct($options); - if (isset($this->_options['servers'])) { - $value= $this->_options['servers']; - if (isset($value['host'])) { - // in this case, $value seems to be a simple associative array (one server only) - $value = array(0 => $value); // let's transform it into a classical array of associative arrays - } - $this->setOption('servers', $value); - } - $this->_memcache = new Memcache; - foreach ($this->_options['servers'] as $server) { - if (!array_key_exists('persistent', $server)) { - $server['persistent'] = Zend_Cache_Backend_Memcached::DEFAULT_PERSISTENT; - } - if (!array_key_exists('port', $server)) { - $server['port'] = Zend_Cache_Backend_Memcached::DEFAULT_PORT; - } - $this->_memcache->addServer($server['host'], $server['port'], $server['persistent']); - } - } - - /** - * Test if a cache is available for the given id and (if yes) return it (false else) - * - * @param string $id Cache id - * @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested - * @return string|false cached datas - */ - public function load($id, $doNotTestCacheValidity = false) - { - // WARNING : $doNotTestCacheValidity is not supported !!! - if ($doNotTestCacheValidity) { - $this->_log("Zend_Cache_Backend_Memcached::load() : \$doNotTestCacheValidity=true is unsupported by the Memcached backend"); - } - - $tmp = $this->_memcache->get($id); - if (is_array($id)) { - if (is_array($tmp)) { - $aDataReturn=array(); - foreach ($tmp as $key => $data) { - if (is_array($data)) { - $aDataReturn[$key]=$data[0]; - } - } - if (count($aDataReturn)>0) { - return $aDataReturn; - } - } - } else { - if (is_array($tmp)) { - return $tmp[0]; - } - } - return false; - } - - /** - * Test if a cache is available or not (for the given id) - * - * @param string $id Cache id - * @return mixed|false (a cache is not available) or "last modified" timestamp (int) of the available cache record - */ - public function test($id) - { - $tmp = $this->_memcache->get($id); - if (is_array($tmp)) { - return $tmp[1]; - } - return false; - } - - /** - * Save some string datas into a cache record - * - * Note : $data is always "string" (serialization is done by the - * core not by the backend) - * - * @param string $data Datas to cache - * @param string $id Cache id - * @param array $tags Array of strings, the cache record will be tagged by each string entry - * @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime) - * @return boolean True if no problem - */ - public function save($data, $id, $tags = array(), $specificLifetime = false) - { - $lifetime = $this->getLifetime($specificLifetime); - if ($this->_options['compression']) { - $flag = MEMCACHE_COMPRESSED; - } else { - $flag = 0; - } - $result = $this->_memcache->set($id, array($data, time()), $flag, $lifetime); - if (count($tags) > 0) { - $this->_log("Zend_Cache_Backend_Memcached::save() : tags are unsupported by the Memcached backend"); - } - return $result; - } - - /** - * Remove a cache record - * - * @param string $id Cache id - * @return boolean True if no problem - */ - public function remove($id) - { - return $this->_memcache->delete($id,0); - } - - /** - * Clean some cache records - * - * Available modes are : - * 'all' (default) => remove all cache entries ($tags is not used) - * 'old' => remove too old cache entries ($tags is not used) - * 'matchingTag' => remove cache entries matching all given tags - * ($tags can be an array of strings or a single string) - * 'notMatchingTag' => remove cache entries not matching one of the given tags - * ($tags can be an array of strings or a single string) - * - * @param string $mode Clean mode - * @param array $tags Array of tags - * @return boolean True if no problem - */ - public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array()) - { - if ($mode==Zend_Cache::CLEANING_MODE_ALL) { - return $this->_memcache->flush(); - } - if ($mode==Zend_Cache::CLEANING_MODE_OLD) { - $this->_log("Zend_Cache_Backend_Memcached::clean() : CLEANING_MODE_OLD is unsupported by the Memcached backend"); - } - if ($mode==Zend_Cache::CLEANING_MODE_MATCHING_TAG) { - $this->_log("Zend_Cache_Backend_Memcached::clean() : tags are unsupported by the Memcached backend"); - } - if ($mode==Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG) { - $this->_log("Zend_Cache_Backend_Memcached::clean() : tags are unsupported by the Memcached backend"); - } - } - - /** - * Return true if the automatic cleaning is available for the backend - * - * @return boolean - */ - public function isAutomaticCleaningAvailable() - { - return false; - } - -} diff --git a/framework/libs/vendor/DklabCache/Zend/Cache/Backend/Xcache.php b/framework/libs/vendor/DklabCache/Zend/Cache/Backend/Xcache.php deleted file mode 100644 index 9f39047..0000000 --- a/framework/libs/vendor/DklabCache/Zend/Cache/Backend/Xcache.php +++ /dev/null @@ -1,221 +0,0 @@ - (string) user : - * xcache.admin.user (necessary for the clean() method) - * - * =====> (string) password : - * xcache.admin.pass (clear, not MD5) (necessary for the clean() method) - * - * @var array available options - */ - protected $_options = array( - 'user' => null, - 'password' => null - ); - - /** - * Constructor - * - * @param array $options associative array of options - * @throws Zend_Cache_Exception - * @return void - */ - public function __construct(array $options = array()) - { - if (!extension_loaded('xcache')) { - Zend_Cache::throwException('The xcache extension must be loaded for using this backend !'); - } - parent::__construct($options); - } - - /** - * Test if a cache is available for the given id and (if yes) return it (false else) - * - * WARNING $doNotTestCacheValidity=true is unsupported by the Xcache backend - * - * @param string $id cache id - * @param boolean $doNotTestCacheValidity if set to true, the cache validity won't be tested - * @return string cached datas (or false) - */ - public function load($id, $doNotTestCacheValidity = false) - { - if ($doNotTestCacheValidity) { - $this->_log("Zend_Cache_Backend_Xcache::load() : \$doNotTestCacheValidity=true is unsupported by the Xcache backend"); - } - $tmp = xcache_get($id); - if (is_array($tmp)) { - return $tmp[0]; - } - return false; - } - - /** - * Test if a cache is available or not (for the given id) - * - * @param string $id cache id - * @return mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record - */ - public function test($id) - { - if (xcache_isset($id)) { - $tmp = xcache_get($id); - if (is_array($tmp)) { - return $tmp[1]; - } - } - return false; - } - - /** - * Save some string datas into a cache record - * - * Note : $data is always "string" (serialization is done by the - * core not by the backend) - * - * @param string $data datas to cache - * @param string $id cache id - * @param array $tags array of strings, the cache record will be tagged by each string entry - * @param int $specificLifetime if != false, set a specific lifetime for this cache record (null => infinite lifetime) - * @return boolean true if no problem - */ - public function save($data, $id, $tags = array(), $specificLifetime = false) - { - $lifetime = $this->getLifetime($specificLifetime); - $result = xcache_set($id, array($data, time()), $lifetime); - if (count($tags) > 0) { - $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_XCACHE_BACKEND); - } - return $result; - } - - /** - * Remove a cache record - * - * @param string $id cache id - * @return boolean true if no problem - */ - public function remove($id) - { - return xcache_unset($id); - } - - /** - * Clean some cache records - * - * Available modes are : - * 'all' (default) => remove all cache entries ($tags is not used) - * 'old' => unsupported - * 'matchingTag' => unsupported - * 'notMatchingTag' => unsupported - * 'matchingAnyTag' => unsupported - * - * @param string $mode clean mode - * @param array $tags array of tags - * @throws Zend_Cache_Exception - * @return boolean true if no problem - */ - public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array()) - { - switch ($mode) { - case Zend_Cache::CLEANING_MODE_ALL: - // Necessary because xcache_clear_cache() need basic authentification - $backup = array(); - if (isset($_SERVER['PHP_AUTH_USER'])) { - $backup['PHP_AUTH_USER'] = $_SERVER['PHP_AUTH_USER']; - } - if (isset($_SERVER['PHP_AUTH_PW'])) { - $backup['PHP_AUTH_PW'] = $_SERVER['PHP_AUTH_PW']; - } - if ($this->_options['user']) { - $_SERVER['PHP_AUTH_USER'] = $this->_options['user']; - } - if ($this->_options['password']) { - $_SERVER['PHP_AUTH_PW'] = $this->_options['password']; - } - - $cnt = xcache_count(XC_TYPE_VAR); - for ($i=0; $i < $cnt; $i++) { - xcache_clear_cache(XC_TYPE_VAR, $i); - } - - if (isset($backup['PHP_AUTH_USER'])) { - $_SERVER['PHP_AUTH_USER'] = $backup['PHP_AUTH_USER']; - $_SERVER['PHP_AUTH_PW'] = $backup['PHP_AUTH_PW']; - } - return true; - break; - case Zend_Cache::CLEANING_MODE_OLD: - $this->_log("Zend_Cache_Backend_Xcache::clean() : CLEANING_MODE_OLD is unsupported by the Xcache backend"); - break; - case Zend_Cache::CLEANING_MODE_MATCHING_TAG: - case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG: - case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG: - $this->_log(self::TAGS_UNSUPPORTED_BY_CLEAN_OF_XCACHE_BACKEND); - break; - default: - Zend_Cache::throwException('Invalid mode for clean() method'); - break; - } - } - - /** - * Return true if the automatic cleaning is available for the backend - * - * @return boolean - */ - public function isAutomaticCleaningAvailable() - { - return false; - } - -} diff --git a/framework/libs/vendor/DklabCache/Zend/Cache/Exception.php b/framework/libs/vendor/DklabCache/Zend/Cache/Exception.php deleted file mode 100644 index 88058c6..0000000 --- a/framework/libs/vendor/DklabCache/Zend/Cache/Exception.php +++ /dev/null @@ -1,31 +0,0 @@ - \ No newline at end of file