Permalink
Browse files

API CHANGE Updated Zend framework dependency from 1.8.1 to 1.11.6. In…

…cludes changes to the underlying CLDR locale data, which changes the default en_US date format from 'MM/dd/yyyy' to a less ambiguous 'MMM d, y' (before: '01/31/2011', after: 'Dec 1, 2011')
  • Loading branch information...
1 parent 8076b4e commit 9434f87cb9d59306b5d8e904e1fabb60d068af48 @chillu chillu committed May 30, 2011
Showing with 28,262 additions and 23,289 deletions.
  1. +23 −18 thirdparty/Zend/Cache.php
  2. +0 −8 thirdparty/Zend/Cache/.piston.yml
  3. +71 −31 thirdparty/Zend/Cache/Backend.php
  4. +28 −27 thirdparty/Zend/Cache/Backend/Apc.php
  5. +250 −0 thirdparty/Zend/Cache/Backend/BlackHole.php
  6. +17 −16 thirdparty/Zend/Cache/Backend/ExtendedInterface.php
  7. +46 −43 thirdparty/Zend/Cache/Backend/File.php
  8. +3 −2 thirdparty/Zend/Cache/Backend/Interface.php
  9. +484 −0 thirdparty/Zend/Cache/Backend/Libmemcached.php
  10. +36 −33 thirdparty/Zend/Cache/Backend/Memcached.php
  11. +7 −6 thirdparty/Zend/Cache/Backend/Sqlite.php
  12. +564 −0 thirdparty/Zend/Cache/Backend/Static.php
  13. +159 −15 thirdparty/Zend/Cache/Backend/Test.php
  14. +56 −21 thirdparty/Zend/Cache/Backend/TwoLevels.php
  15. +349 −0 thirdparty/Zend/Cache/Backend/WinCache.php
  16. +10 −4 thirdparty/Zend/Cache/Backend/Xcache.php
  17. +3 −2 thirdparty/Zend/Cache/Backend/ZendPlatform.php
  18. +207 −208 thirdparty/Zend/Cache/Backend/ZendServer.php
  19. +100 −101 thirdparty/Zend/Cache/Backend/ZendServer/Disk.php
  20. +100 −101 thirdparty/Zend/Cache/Backend/ZendServer/ShMem.php
  21. +175 −51 thirdparty/Zend/Cache/Core.php
  22. +3 −2 thirdparty/Zend/Cache/Exception.php
  23. +88 −0 thirdparty/Zend/Cache/Frontend/Capture.php
  24. +33 −16 thirdparty/Zend/Cache/Frontend/Class.php
  25. +73 −59 thirdparty/Zend/Cache/Frontend/File.php
  26. +76 −27 thirdparty/Zend/Cache/Frontend/Function.php
  27. +4 −4 thirdparty/Zend/Cache/Frontend/Output.php
  28. +13 −10 thirdparty/Zend/Cache/Frontend/Page.php
  29. +298 −0 thirdparty/Zend/Cache/Manager.php
  30. +333 −63 thirdparty/Zend/Currency.php
  31. +0 −8 thirdparty/Zend/Currency/.piston.yml
  32. +39 −0 thirdparty/Zend/Currency/CurrencyInterface.php
  33. +3 −3 thirdparty/Zend/Currency/Exception.php
  34. +685 −290 thirdparty/Zend/Date.php
  35. +0 −8 thirdparty/Zend/Date/.piston.yml
  36. +3 −3 thirdparty/Zend/Date/Cities.php
  37. +53 −21 thirdparty/Zend/Date/DateObject.php
  38. +5 −5 thirdparty/Zend/Date/Exception.php
  39. +74 −8 thirdparty/Zend/Exception.php
  40. +238 −103 thirdparty/Zend/Locale.php
  41. +0 −8 thirdparty/Zend/Locale/.piston.yml
  42. +218 −17 thirdparty/Zend/Locale/Data.php
  43. +249 −60 thirdparty/Zend/Locale/Data/Translation.php
  44. +220 −260 thirdparty/Zend/Locale/Data/aa.xml
  45. +25 −35 thirdparty/Zend/Locale/Data/aa_DJ.xml
  46. +10 −20 thirdparty/Zend/Locale/Data/aa_ER.xml
  47. +38 −0 thirdparty/Zend/Locale/Data/aa_ER_SAAHO.xml
  48. +9 −10 thirdparty/Zend/Locale/Data/aa_ET.xml
  49. +821 −827 thirdparty/Zend/Locale/Data/af.xml
  50. +74 −76 thirdparty/Zend/Locale/Data/af_NA.xml
  51. +9 −10 thirdparty/Zend/Locale/Data/af_ZA.xml
  52. +189 −195 thirdparty/Zend/Locale/Data/ak.xml
  53. +9 −10 thirdparty/Zend/Locale/Data/ak_GH.xml
  54. +1,409 −1,416 thirdparty/Zend/Locale/Data/am.xml
  55. +9 −10 thirdparty/Zend/Locale/Data/am_ET.xml
  56. +3,118 −3,107 thirdparty/Zend/Locale/Data/ar.xml
  57. +14 −15 thirdparty/Zend/Locale/Data/ar_AE.xml
  58. +14 −15 thirdparty/Zend/Locale/Data/ar_BH.xml
  59. +43 −20 thirdparty/Zend/Locale/Data/ar_DZ.xml
  60. +9 −10 thirdparty/Zend/Locale/Data/ar_EG.xml
  61. +14 −15 thirdparty/Zend/Locale/Data/ar_IQ.xml
  62. +65 −66 thirdparty/Zend/Locale/Data/ar_JO.xml
  63. +14 −15 thirdparty/Zend/Locale/Data/ar_KW.xml
  64. +66 −72 thirdparty/Zend/Locale/Data/ar_LB.xml
  65. +14 −15 thirdparty/Zend/Locale/Data/ar_LY.xml
  66. +46 −20 thirdparty/Zend/Locale/Data/ar_MA.xml
  67. +14 −15 thirdparty/Zend/Locale/Data/ar_OM.xml
  68. +49 −50 thirdparty/Zend/Locale/Data/ar_QA.xml
  69. +49 −50 thirdparty/Zend/Locale/Data/ar_SA.xml
  70. +14 −15 thirdparty/Zend/Locale/Data/ar_SD.xml
  71. +81 −82 thirdparty/Zend/Locale/Data/ar_SY.xml
  72. +74 −54 thirdparty/Zend/Locale/Data/ar_TN.xml
  73. +49 −50 thirdparty/Zend/Locale/Data/ar_YE.xml
  74. +274 −280 thirdparty/Zend/Locale/Data/as.xml
  75. +9 −10 thirdparty/Zend/Locale/Data/as_IN.xml
  76. +2,715 −2,752 thirdparty/Zend/Locale/Data/az.xml
  77. +10 −11 thirdparty/Zend/Locale/Data/az_AZ.xml
  78. +84 −85 thirdparty/Zend/Locale/Data/az_Cyrl.xml
  79. +10 −11 thirdparty/Zend/Locale/Data/az_Cyrl_AZ.xml
  80. +9 −10 thirdparty/Zend/Locale/Data/az_Latn.xml
  81. +10 −11 thirdparty/Zend/Locale/Data/az_Latn_AZ.xml
  82. +1,090 −1,191 thirdparty/Zend/Locale/Data/be.xml
  83. +9 −10 thirdparty/Zend/Locale/Data/be_BY.xml
  84. +3,960 −3,014 thirdparty/Zend/Locale/Data/bg.xml
  85. +9 −10 thirdparty/Zend/Locale/Data/bg_BG.xml
  86. +2,834 −2,919 thirdparty/Zend/Locale/Data/bn.xml
  87. +9 −10 thirdparty/Zend/Locale/Data/bn_BD.xml
  88. +35 −194 thirdparty/Zend/Locale/Data/bn_IN.xml
  89. +440 −0 thirdparty/Zend/Locale/Data/bo.xml
  90. +9 −0 thirdparty/Zend/Locale/Data/bo_CN.xml
  91. +9 −0 thirdparty/Zend/Locale/Data/bo_IN.xml
  92. +329 −337 thirdparty/Zend/Locale/Data/bs.xml
  93. +9 −10 thirdparty/Zend/Locale/Data/bs_BA.xml
  94. +501 −508 thirdparty/Zend/Locale/Data/byn.xml
  95. +9 −10 thirdparty/Zend/Locale/Data/byn_ER.xml
  96. +3,252 −1,644 thirdparty/Zend/Locale/Data/ca.xml
  97. +9 −10 thirdparty/Zend/Locale/Data/ca_ES.xml
  98. +188 −194 thirdparty/Zend/Locale/Data/cch.xml
  99. +9 −10 thirdparty/Zend/Locale/Data/cch_NG.xml
  100. +489 −1,888 thirdparty/Zend/Locale/Data/characters.xml
  101. +197 −203 thirdparty/Zend/Locale/Data/cop.xml
Sorry, we could not display the entire diff because too many files (548) changed.
View
41 thirdparty/Zend/Cache.php
@@ -14,15 +14,15 @@
*
* @category Zend
* @package Zend_Cache
- * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
- * @version $Id: Cache.php 12519 2008-11-10 18:41:24Z alexander $
+ * @version $Id: Cache.php 23775 2011-03-01 17:25:24Z ralph $
*/
/**
* @package Zend_Cache
- * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Cache
@@ -40,30 +40,31 @@
*
* @var array
*/
- public static $standardBackends = array('File', 'Sqlite', 'Memcached', 'Apc', 'ZendPlatform', 'Xcache', 'TwoLevels');
+ public static $standardBackends = array('File', 'Sqlite', 'Memcached', 'Libmemcached', 'Apc', 'ZendPlatform',
+ 'Xcache', 'TwoLevels', 'WinCache', 'ZendServer_Disk', 'ZendServer_ShMem');
/**
* Standard backends which implement the ExtendedInterface
- *
+ *
* @var array
*/
- public static $standardExtendedBackends = array('File', 'Apc', 'TwoLevels', 'Memcached', 'Sqlite');
-
+ public static $standardExtendedBackends = array('File', 'Apc', 'TwoLevels', 'Memcached', 'Libmemcached', 'Sqlite', 'WinCache');
+
/**
- * Only for backward compatibily (may be removed in next major release)
+ * Only for backward compatibility (may be removed in next major release)
*
* @var array
* @deprecated
*/
public static $availableFrontends = array('Core', 'Output', 'Class', 'File', 'Function', 'Page');
/**
- * Only for backward compatibily (may be removed in next major release)
+ * Only for backward compatibility (may be removed in next major release)
*
* @var array
* @deprecated
*/
- public static $availableBackends = array('File', 'Sqlite', 'Memcached', 'Apc', 'ZendPlatform', 'Xcache', 'TwoLevels');
+ public static $availableBackends = array('File', 'Sqlite', 'Memcached', 'Libmemcached', 'Apc', 'ZendPlatform', 'Xcache', 'WinCache', 'TwoLevels');
/**
* Consts for clean() method
@@ -73,7 +74,7 @@
const CLEANING_MODE_MATCHING_TAG = 'matchingTag';
const CLEANING_MODE_NOT_MATCHING_TAG = 'notMatchingTag';
const CLEANING_MODE_MATCHING_ANY_TAG = 'matchingAnyTag';
-
+
/**
* Factory
*
@@ -83,7 +84,7 @@
* @param array $backendOptions associative array of options for the corresponding backend constructor
* @param boolean $customFrontendNaming if true, the frontend argument is used as a complete class name ; if false, the frontend argument is used as the end of "Zend_Cache_Frontend_[...]" class name
* @param boolean $customBackendNaming if true, the backend argument is used as a complete class name ; if false, the backend argument is used as the end of "Zend_Cache_Backend_[...]" class name
- * @param boolean $autoload if true, there will no require_once for backend and frontend (usefull only for custom backends/frontends)
+ * @param boolean $autoload if true, there will no require_once for backend and frontend (useful only for custom backends/frontends)
* @throws Zend_Cache_Exception
* @return Zend_Cache_Core|Zend_Cache_Frontend
*/
@@ -110,9 +111,9 @@ public static function factory($frontend, $backend, $frontendOptions = array(),
$frontendObject->setBackend($backendObject);
return $frontendObject;
}
-
+
/**
- * Frontend Constructor
+ * Backend Constructor
*
* @param string $backend
* @param array $backendOptions
@@ -151,9 +152,9 @@ public static function _makeBackend($backend, $backendOptions, $customBackendNam
}
return new $backendClass($backendOptions);
}
-
+
/**
- * Backend Constructor
+ * Frontend Constructor
*
* @param string $frontend
* @param array $frontendOptions
@@ -201,11 +202,11 @@ public static function _makeFrontend($frontend, $frontendOptions = array(), $cus
* @param string $msg Message for the exception
* @throws Zend_Cache_Exception
*/
- public static function throwException($msg)
+ public static function throwException($msg, Exception $e = null)
{
// For perfs reasons, we use this dynamic inclusion
require_once 'Zend/Cache/Exception.php';
- throw new Zend_Cache_Exception($msg);
+ throw new Zend_Cache_Exception($msg, 0, $e);
}
/**
@@ -220,6 +221,10 @@ protected static function _normalizeName($name)
$name = str_replace(array('-', '_', '.'), ' ', $name);
$name = ucwords($name);
$name = str_replace(' ', '', $name);
+ if (stripos($name, 'ZendServer') === 0) {
+ $name = 'ZendServer_' . substr($name, strlen('ZendServer'));
+ }
+
return $name;
}
View
8 thirdparty/Zend/Cache/.piston.yml
@@ -1,8 +0,0 @@
----
-format: 1
-handler:
- piston:remote-revision: 17373
- piston:uuid: 44c647ce-9c0f-0410-b52a-842ac1e357ba
-lock: false
-repository_url: http://framework.zend.com/svn/framework/standard/tags/release-1.8.1/library/Zend/Cache
-repository_class: Piston::Svn::Repository
View
102 thirdparty/Zend/Cache/Backend.php
@@ -15,15 +15,16 @@
* @category Zend
* @package Zend_Cache
* @subpackage Zend_Cache_Backend
- * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id: Backend.php 23800 2011-03-10 20:52:08Z mabe $
*/
/**
* @package Zend_Cache
* @subpackage Zend_Cache_Backend
- * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Cache_Backend
@@ -141,32 +142,75 @@ public function isAutomaticCleaningAvailable()
}
/**
- * Return a system-wide tmp directory
+ * Determine system TMP directory and detect if we have read access
*
- * @return string System-wide tmp directory
+ * inspired from Zend_File_Transfer_Adapter_Abstract
+ *
+ * @return string
+ * @throws Zend_Cache_Exception if unable to determine directory
*/
- static function getTmpDir()
+ public 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;
+ $tmpdir = array();
+ foreach (array($_ENV, $_SERVER) as $tab) {
+ foreach (array('TMPDIR', 'TEMP', 'TMP', 'windir', 'SystemRoot') as $key) {
+ if (isset($tab[$key])) {
+ if (($key == 'windir') or ($key == 'SystemRoot')) {
+ $dir = realpath($tab[$key] . '\\temp');
+ } else {
+ $dir = realpath($tab[$key]);
+ }
+ if ($this->_isGoodTmpDir($dir)) {
+ return $dir;
}
}
}
- return '\\temp';
- } else {
- // unix...
- if (isset($_ENV['TMPDIR'])) return $_ENV['TMPDIR'];
- if (isset($_SERVER['TMPDIR'])) return $_SERVER['TMPDIR'];
+ }
+ $upload = ini_get('upload_tmp_dir');
+ if ($upload) {
+ $dir = realpath($upload);
+ if ($this->_isGoodTmpDir($dir)) {
+ return $dir;
+ }
+ }
+ if (function_exists('sys_get_temp_dir')) {
+ $dir = sys_get_temp_dir();
+ if ($this->_isGoodTmpDir($dir)) {
+ return $dir;
+ }
+ }
+ // Attemp to detect by creating a temporary file
+ $tempFile = tempnam(md5(uniqid(rand(), TRUE)), '');
+ if ($tempFile) {
+ $dir = realpath(dirname($tempFile));
+ unlink($tempFile);
+ if ($this->_isGoodTmpDir($dir)) {
+ return $dir;
+ }
+ }
+ if ($this->_isGoodTmpDir('/tmp')) {
return '/tmp';
}
+ if ($this->_isGoodTmpDir('\\temp')) {
+ return '\\temp';
+ }
+ Zend_Cache::throwException('Could not determine temp directory, please specify a cache_dir manually');
+ }
+
+ /**
+ * Verify if the given temporary directory is readable and writable
+ *
+ * @param string $dir temporary directory
+ * @return boolean true if the directory is ok
+ */
+ protected function _isGoodTmpDir($dir)
+ {
+ if (is_readable($dir)) {
+ if (is_writable($dir)) {
+ return true;
+ }
+ }
+ return false;
}
/**
@@ -182,24 +226,20 @@ protected function _loggerSanity()
if (!isset($this->_directives['logging']) || !$this->_directives['logging']) {
return;
}
- try {
- /**
- * @see Zend_Log
- */
- require_once 'Zend/Log.php';
- } catch (Zend_Exception $e) {
- Zend_Cache::throwException('Logging feature is enabled but the Zend_Log class is not available');
- }
+
if (isset($this->_directives['logger'])) {
if ($this->_directives['logger'] instanceof Zend_Log) {
return;
- } else {
- Zend_Cache::throwException('Logger object is not an instance of Zend_Log class.');
}
+ Zend_Cache::throwException('Logger object is not an instance of Zend_Log class.');
}
+
// Create a default logger to the standard output stream
+ require_once 'Zend/Log.php';
require_once 'Zend/Log/Writer/Stream.php';
+ require_once 'Zend/Log/Filter/Priority.php';
$logger = new Zend_Log(new Zend_Log_Writer_Stream('php://output'));
+ $logger->addFilter(new Zend_Log_Filter_Priority(Zend_Log::WARN, '<='));
$this->_directives['logger'] = $logger;
}
@@ -217,7 +257,7 @@ protected function _log($message, $priority = 4)
}
if (!isset($this->_directives['logger'])) {
- Zend_Cache::throwException('Logging is enabled but logger is not set.');
+ Zend_Cache::throwException('Logging is enabled but logger is not set.');
}
$logger = $this->_directives['logger'];
if (!$logger instanceof Zend_Log) {
View
55 thirdparty/Zend/Cache/Backend/Apc.php
@@ -15,8 +15,9 @@
* @category Zend
* @package Zend_Cache
* @subpackage Zend_Cache_Backend
- * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id: Apc.php 23775 2011-03-01 17:25:24Z ralph $
*/
@@ -34,7 +35,7 @@
/**
* @package Zend_Cache
* @subpackage Zend_Cache_Backend
- * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Cache_Backend_Apc extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface
@@ -165,18 +166,18 @@ public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
* Return true if the automatic cleaning is available for the backend
*
* DEPRECATED : use getCapabilities() instead
- *
- * @deprecated
+ *
+ * @deprecated
* @return boolean
*/
public function isAutomaticCleaningAvailable()
{
return false;
}
-
+
/**
* Return the filling percentage of the backend storage
- *
+ *
* @throws Zend_Cache_Exception
* @return int integer between 0 and 100
*/
@@ -194,21 +195,21 @@ public function getFillingPercentage()
}
return ((int) (100. * ($memUsed / $memSize)));
}
-
+
/**
* Return an array of stored tags
*
* @return array array of stored tags (string)
*/
public function getTags()
- {
+ {
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_APC_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
@@ -217,26 +218,26 @@ public function getTags()
public function getIdsMatchingTags($tags = array())
{
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND);
- return array();
+ 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_APC_BACKEND);
- return array();
+ 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
@@ -245,12 +246,12 @@ public function getIdsNotMatchingTags($tags = array())
public function getIdsMatchingAnyTags($tags = array())
{
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND);
- return array();
+ return array();
}
-
+
/**
* Return an array of stored cache ids
- *
+ *
* @return array array of stored cache ids (string)
*/
public function getIds()
@@ -263,15 +264,15 @@ public function getIds()
}
return $res;
}
-
+
/**
* 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)
*/
@@ -293,9 +294,9 @@ public function getMetadatas($id)
'mtime' => $mtime
);
}
- return false;
+ return false;
}
-
+
/**
* Give (if possible) an extra lifetime to the given cache id
*
@@ -317,17 +318,17 @@ public function touch($id, $extraLifetime)
$lifetime = $tmp[2];
$newLifetime = $lifetime - (time() - $mtime) + $extraLifetime;
if ($newLifetime <=0) {
- return false;
+ return false;
}
apc_store($id, array($data, time(), $newLifetime), $newLifetime);
return true;
}
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)
@@ -336,7 +337,7 @@ public function touch($id, $extraLifetime)
* - 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()
View
250 thirdparty/Zend/Cache/Backend/BlackHole.php
@@ -0,0 +1,250 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Cache
+ * @subpackage Zend_Cache_Backend
+ * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id: BlackHole.php 23775 2011-03-01 17:25:24Z ralph $
+ */
+
+/**
+ * @see Zend_Cache_Backend_Interface
+ */
+require_once 'Zend/Cache/Backend/ExtendedInterface.php';
+
+/**
+ * @see Zend_Cache_Backend
+ */
+require_once 'Zend/Cache/Backend.php';
+
+/**
+ * @package Zend_Cache
+ * @subpackage Zend_Cache_Backend
+ * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+class Zend_Cache_Backend_BlackHole
+ extends Zend_Cache_Backend
+ implements Zend_Cache_Backend_ExtendedInterface
+{
+ /**
+ * 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)
+ {
+ 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)
+ {
+ 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)
+ {
+ return true;
+ }
+
+ /**
+ * Remove a cache record
+ *
+ * @param string $id cache id
+ * @return boolean true if no problem
+ */
+ public function remove($id)
+ {
+ return true;
+ }
+
+ /**
+ * 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)
+ * 'matchingAnyTag' => remove cache entries matching any 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())
+ {
+ return true;
+ }
+
+ /**
+ * Return an array of stored cache ids
+ *
+ * @return array array of stored cache ids (string)
+ */
+ public function getIds()
+ {
+ return array();
+ }
+
+ /**
+ * Return an array of stored tags
+ *
+ * @return array array of stored tags (string)
+ */
+ public function getTags()
+ {
+ 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())
+ {
+ 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())
+ {
+ 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())
+ {
+ return array();
+ }
+
+ /**
+ * Return the filling percentage of the backend storage
+ *
+ * @return int integer between 0 and 100
+ * @throws Zend_Cache_Exception
+ */
+ public function getFillingPercentage()
+ {
+ return 0;
+ }
+
+ /**
+ * 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)
+ {
+ 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)
+ {
+ 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' => true,
+ 'tags' => true,
+ 'expired_read' => true,
+ 'priority' => true,
+ 'infinite_lifetime' => true,
+ 'get_list' => true,
+ );
+ }
+
+ /**
+ * PUBLIC METHOD FOR UNIT TESTING ONLY !
+ *
+ * Force a cache record to expire
+ *
+ * @param string $id cache id
+ */
+ public function ___expire($id)
+ {
+ }
+}
View
33 thirdparty/Zend/Cache/Backend/ExtendedInterface.php
@@ -15,8 +15,9 @@
* @category Zend
* @package Zend_Cache
* @subpackage Zend_Cache_Backend
- * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id: ExtendedInterface.php 23775 2011-03-01 17:25:24Z ralph $
*/
/**
@@ -27,29 +28,29 @@
/**
* @package Zend_Cache
* @subpackage Zend_Cache_Backend
- * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Cache_Backend_ExtendedInterface extends Zend_Cache_Backend_Interface
{
/**
* Return an array of stored cache ids
- *
+ *
* @return array array of stored cache ids (string)
*/
public function getIds();
-
+
/**
* Return an array of stored tags
*
* @return array array of stored tags (string)
*/
public function getTags();
-
+
/**
* 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
@@ -59,24 +60,24 @@ public function getIdsMatchingTags($tags = 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());
/**
* 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());
-
+
/**
* Return the filling percentage of the backend storage
*
@@ -91,12 +92,12 @@ public function getFillingPercentage();
* - 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);
-
+
/**
* Give (if possible) an extra lifetime to the given cache id
*
@@ -105,10 +106,10 @@ public function getMetadatas($id);
* @return boolean true if ok
*/
public function touch($id, $extraLifetime);
-
+
/**
* 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)
@@ -117,9 +118,9 @@ public function touch($id, $extraLifetime);
* - 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();
-
+
}
View
89 thirdparty/Zend/Cache/Backend/File.php
@@ -15,8 +15,9 @@
* @category Zend
* @package Zend_Cache
* @subpackage Zend_Cache_Backend
- * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id: File.php 23775 2011-03-01 17:25:24Z ralph $
*/
/**
@@ -33,7 +34,7 @@
/**
* @package Zend_Cache
* @subpackage Zend_Cache_Backend
- * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Cache_Backend_File extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface
@@ -103,7 +104,7 @@ class Zend_Cache_Backend_File extends Zend_Cache_Backend implements Zend_Cache_B
*
* @var array
*/
- private $_metadatasArray = array();
+ protected $_metadatasArray = array();
/**
@@ -122,8 +123,8 @@ public function __construct(array $options = array())
$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 (!preg_match('~^[a-zA-Z0-9_]+$~D', $this->_options['file_name_prefix'])) {
+ Zend_Cache::throwException('Invalid file_name_prefix : must use only [a-zA-Z0-9_]');
}
}
if ($this->_options['metadatas_array_max_size'] < 10) {
@@ -258,7 +259,9 @@ public function save($data, $id, $tags = array(), $specificLifetime = false)
public function remove($id)
{
$file = $this->_file($id);
- return ($this->_delMetadatas($id) && $this->_remove($file));
+ $boolRemove = $this->_remove($file);
+ $boolMetadata = $this->_delMetadatas($id);
+ return $boolMetadata && $boolRemove;
}
/**
@@ -280,7 +283,7 @@ public function remove($id)
*/
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
{
- // We use this private method to hide the recursive stuff
+ // We use this protected method to hide the recursive stuff
clearstatcache();
return $this->_clean($this->_options['cache_dir'], $mode, $tags);
}
@@ -468,7 +471,7 @@ public function ___expire($id)
* @param string $id Cache id
* @return array|false Associative array of metadatas
*/
- private function _getMetadatas($id)
+ protected function _getMetadatas($id)
{
if (isset($this->_metadatasArray[$id])) {
return $this->_metadatasArray[$id];
@@ -490,7 +493,7 @@ private function _getMetadatas($id)
* @param boolean $save optional pass false to disable saving to file
* @return boolean True if no problem
*/
- private function _setMetadatas($id, $metadatas, $save = true)
+ protected 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);
@@ -512,7 +515,7 @@ private function _setMetadatas($id, $metadatas, $save = true)
* @param string $id Cache id
* @return boolean True if no problem
*/
- private function _delMetadatas($id)
+ protected function _delMetadatas($id)
{
if (isset($this->_metadatasArray[$id])) {
unset($this->_metadatasArray[$id]);
@@ -526,7 +529,7 @@ private function _delMetadatas($id)
*
* @return void
*/
- private function _cleanMetadatas()
+ protected function _cleanMetadatas()
{
$this->_metadatasArray = array();
}
@@ -537,7 +540,7 @@ private function _cleanMetadatas()
* @param string $id Cache id
* @return array|false Metadatas associative array
*/
- private function _loadMetadatas($id)
+ protected function _loadMetadatas($id)
{
$file = $this->_metadatasFile($id);
$result = $this->_fileGetContents($file);
@@ -555,7 +558,7 @@ private function _loadMetadatas($id)
* @param array $metadatas Associative array
* @return boolean True if no problem
*/
- private function _saveMetadatas($id, $metadatas)
+ protected function _saveMetadatas($id, $metadatas)
{
$file = $this->_metadatasFile($id);
$result = $this->_filePutContents($file, serialize($metadatas));
@@ -571,7 +574,7 @@ private function _saveMetadatas($id, $metadatas)
* @param string $id Cache id
* @return string Metadatas file name (with path)
*/
- private function _metadatasFile($id)
+ protected function _metadatasFile($id)
{
$path = $this->_path($id);
$fileName = $this->_idToFileName('internal-metadatas---' . $id);
@@ -584,7 +587,7 @@ private function _metadatasFile($id)
* @param string $fileName File name
* @return boolean True if it's a metadatas one
*/
- private function _isMetadatasFile($fileName)
+ protected function _isMetadatasFile($fileName)
{
$id = $this->_fileNameToId($fileName);
if (substr($id, 0, 21) == 'internal-metadatas---') {
@@ -603,7 +606,7 @@ private function _isMetadatasFile($fileName)
* @param string $file Complete file path
* @return boolean True if ok
*/
- private function _remove($file)
+ protected function _remove($file)
{
if (!is_file($file)) {
return false;
@@ -617,7 +620,7 @@ private function _remove($file)
}
/**
- * Clean some cache records (private method used for recursive stuff)
+ * Clean some cache records (protected method used for recursive stuff)
*
* Available modes are :
* Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used)
@@ -635,7 +638,7 @@ private function _remove($file)
* @throws Zend_Cache_Exception
* @return boolean True if no problem
*/
- private function _clean($dir, $mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
+ protected function _clean($dir, $mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
{
if (!is_dir($dir)) {
return false;
@@ -644,6 +647,7 @@ private function _clean($dir, $mode = Zend_Cache::CLEANING_MODE_ALL, $tags = arr
$prefix = $this->_options['file_name_prefix'];
$glob = @glob($dir . $prefix . '--*');
if ($glob === false) {
+ // On some systems it is impossible to distinguish between empty match and an error.
return true;
}
foreach ($glob as $file) {
@@ -671,7 +675,7 @@ private function _clean($dir, $mode = Zend_Cache::CLEANING_MODE_ALL, $tags = arr
break;
case Zend_Cache::CLEANING_MODE_OLD:
if (time() > $metadatas['expire']) {
- $result = ($result) && ($this->remove($id));
+ $result = $this->remove($id) && $result;
}
break;
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
@@ -683,7 +687,7 @@ private function _clean($dir, $mode = Zend_Cache::CLEANING_MODE_ALL, $tags = arr
}
}
if ($matching) {
- $result = ($result) && ($this->remove($id));
+ $result = $this->remove($id) && $result;
}
break;
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
@@ -695,7 +699,7 @@ private function _clean($dir, $mode = Zend_Cache::CLEANING_MODE_ALL, $tags = arr
}
}
if (!$matching) {
- $result = ($result) && $this->remove($id);
+ $result = $this->remove($id) && $result;
}
break;
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
@@ -707,7 +711,7 @@ private function _clean($dir, $mode = Zend_Cache::CLEANING_MODE_ALL, $tags = arr
}
}
if ($matching) {
- $result = ($result) && ($this->remove($id));
+ $result = $this->remove($id) && $result;
}
break;
default:
@@ -717,7 +721,7 @@ private function _clean($dir, $mode = Zend_Cache::CLEANING_MODE_ALL, $tags = arr
}
if ((is_dir($file)) and ($this->_options['hashed_directory_level']>0)) {
// Recursive call
- $result = ($result) && ($this->_clean($file . DIRECTORY_SEPARATOR, $mode, $tags));
+ $result = $this->_clean($file . DIRECTORY_SEPARATOR, $mode, $tags) && $result;
if ($mode=='all') {
// if mode=='all', we try to drop the structure too
@rmdir($file);
@@ -727,7 +731,7 @@ private function _clean($dir, $mode = Zend_Cache::CLEANING_MODE_ALL, $tags = arr
return $result;
}
- private function _get($dir, $mode, $tags = array())
+ protected function _get($dir, $mode, $tags = array())
{
if (!is_dir($dir)) {
return false;
@@ -736,7 +740,8 @@ private function _get($dir, $mode, $tags = array())
$prefix = $this->_options['file_name_prefix'];
$glob = @glob($dir . $prefix . '--*');
if ($glob === false) {
- return true;
+ // On some systems it is impossible to distinguish between empty match and an error.
+ return array();
}
foreach ($glob as $file) {
if (is_file($file)) {
@@ -799,7 +804,12 @@ private function _get($dir, $mode, $tags = array())
}
if ((is_dir($file)) and ($this->_options['hashed_directory_level']>0)) {
// Recursive call
- $result = array_unique(array_merge($result, $this->_get($file . DIRECTORY_SEPARATOR, $mode, $tags)));
+ $recursiveRs = $this->_get($file . DIRECTORY_SEPARATOR, $mode, $tags);
+ if ($recursiveRs === false) {
+ $this->_log('Zend_Cache_Backend_File::_get() / recursive call : can\'t list entries of "'.$file.'"');
+ } else {
+ $result = array_unique(array_merge($result, $recursiveRs));
+ }
}
}
return array_unique($result);
@@ -810,7 +820,7 @@ private function _get($dir, $mode, $tags = array())
*
* @return int expire time (unix timestamp)
*/
- private function _expireTime($lifetime)
+ protected function _expireTime($lifetime)
{
if ($lifetime === null) {
return 9999999999;
@@ -826,7 +836,7 @@ private function _expireTime($lifetime)
* @throws Zend_Cache_Exception
* @return string Control key
*/
- private function _hash($data, $controlType)
+ protected function _hash($data, $controlType)
{
switch ($controlType) {
case 'md5':
@@ -848,7 +858,7 @@ private function _hash($data, $controlType)
* @param string $id Cache id
* @return string File name
*/
- private function _idToFileName($id)
+ protected function _idToFileName($id)
{
$prefix = $this->_options['file_name_prefix'];
$result = $prefix . '---' . $id;
@@ -861,7 +871,7 @@ private function _idToFileName($id)
* @param string $id Cache id
* @return string File name (with path)
*/
- private function _file($id)
+ protected function _file($id)
{
$path = $this->_path($id);
$fileName = $this->_idToFileName($id);
@@ -875,7 +885,7 @@ private function _file($id)
* @param boolean $parts if true, returns array of directory parts instead of single string
* @return string Complete directory path
*/
- private function _path($id, $parts = false)
+ protected function _path($id, $parts = false)
{
$partsArray = array();
$root = $this->_options['cache_dir'];
@@ -900,7 +910,7 @@ private function _path($id, $parts = false)
* @param string $id cache id
* @return boolean true
*/
- private function _recursiveMkdirAndChmod($id)
+ protected function _recursiveMkdirAndChmod($id)
{
if ($this->_options['hashed_directory_level'] <=0) {
return true;
@@ -922,7 +932,7 @@ private function _recursiveMkdirAndChmod($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)
+ protected function _test($id, $doNotTestCacheValidity)
{
$metadatas = $this->_getMetadatas($id);
if (!$metadatas) {
@@ -940,26 +950,19 @@ private function _test($id, $doNotTestCacheValidity)
* @param string $file File complete path
* @return string File content (or false if problem)
*/
- private function _fileGetContents($file)
+ protected function _fileGetContents($file)
{
$result = false;
if (!is_file($file)) {
return false;
}
- if (function_exists('get_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;
}
@@ -970,7 +973,7 @@ private function _fileGetContents($file)
* @param string $string String to put in file
* @return boolean true if no problem
*/
- private function _filePutContents($file, $string)
+ protected function _filePutContents($file, $string)
{
$result = false;
$f = @fopen($file, 'ab+');
@@ -994,7 +997,7 @@ private function _filePutContents($file, $string)
* @param string $fileName File name
* @return string Cache id
*/
- private function _fileNameToId($fileName)
+ protected function _fileNameToId($fileName)
{
$prefix = $this->_options['file_name_prefix'];
return preg_replace('~^' . $prefix . '---(.*)$~', '$1', $fileName);
View
5 thirdparty/Zend/Cache/Backend/Interface.php
@@ -15,15 +15,16 @@
* @category Zend
* @package Zend_Cache
* @subpackage Zend_Cache_Backend
- * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id: Interface.php 23775 2011-03-01 17:25:24Z ralph $
*/
/**
* @package Zend_Cache
* @subpackage Zend_Cache_Backend
- * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Cache_Backend_Interface
View
484 thirdparty/Zend/Cache/Backend/Libmemcached.php
@@ -0,0 +1,484 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Cache
+ * @subpackage Zend_Cache_Backend
+ * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id: Libmemcached.php 23775 2011-03-01 17:25:24Z ralph $
+ */
+
+
+/**
+ * @see Zend_Cache_Backend_Interface
+ */
+require_once 'Zend/Cache/Backend/ExtendedInterface.php';
+
+/**
+ * @see Zend_Cache_Backend
+ */
+require_once 'Zend/Cache/Backend.php';
+
+
+/**
+ * @package Zend_Cache
+ * @subpackage Zend_Cache_Backend
+ * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+class Zend_Cache_Backend_Libmemcached extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface
+{
+ /**
+ * Default Server Values
+ */
+ const DEFAULT_HOST = '127.0.0.1';
+ const DEFAULT_PORT = 11211;
+ const DEFAULT_WEIGHT = 1;
+
+ /**
+ * Log message
+ */
+ const TAGS_UNSUPPORTED_BY_CLEAN_OF_LIBMEMCACHED_BACKEND = 'Zend_Cache_Backend_Libmemcached::clean() : tags are unsupported by the Libmemcached backend';
+ const TAGS_UNSUPPORTED_BY_SAVE_OF_LIBMEMCACHED_BACKEND = 'Zend_Cache_Backend_Libmemcached::save() : tags are unsupported by the Libmemcached backend';
+
+ /**
+ * Available options
+ *
+ * =====> (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 ($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
+ );
+ }
+
+}
View
69 thirdparty/Zend/Cache/Backend/Memcached.php
@@ -15,8 +15,9 @@
* @category Zend
* @package Zend_Cache
* @subpackage Zend_Cache_Backend
- * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id: Memcached.php 23775 2011-03-01 17:25:24Z ralph $
*/
@@ -34,7 +35,7 @@
/**
* @package Zend_Cache
* @subpackage Zend_Cache_Backend
- * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Cache_Backend_Memcached extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface
@@ -154,16 +155,16 @@ public function __construct(array $options = array())
$server['failure_callback'] = self::DEFAULT_FAILURE_CALLBACK;
}
if ($this->_options['compatibility']) {
- // No status for compatibility mode (#ZF-5887)
- $this->_memcache->addServer($server['host'], $server['port'], $server['persistent'],
+ // No status for compatibility mode (#ZF-5887)
+ $this->_memcache->addServer($server['host'], $server['port'], $server['persistent'],
$server['weight'], $server['timeout'],
$server['retry_interval']);
- } else {
- $this->_memcache->addServer($server['host'], $server['port'], $server['persistent'],
+ } else {
+ $this->_memcache->addServer($server['host'], $server['port'], $server['persistent'],
$server['weight'], $server['timeout'],
$server['retry_interval'],
$server['status'], $server['failure_callback']);
- }
+ }
}
}
@@ -177,7 +178,7 @@ public function __construct(array $options = array())
public function load($id, $doNotTestCacheValidity = false)
{
$tmp = $this->_memcache->get($id);
- if (is_array($tmp)) {
+ if (is_array($tmp) && isset($tmp[0])) {
return $tmp[0];
}
return false;
@@ -218,13 +219,14 @@ public function save($data, $id, $tags = array(), $specificLifetime = false)
} else {
$flag = 0;
}
- // #ZF-5702 : we try add() first becase set() seems to be slower
- if (!($result = $this->_memcache->add($id, array($data, time(), $lifetime), $flag, $lifetime))) {
- $result = $this->_memcache->set($id, array($data, time(), $lifetime), $flag, $lifetime);
- }
+
+ // ZF-8856: using set because add needs a second request if item already exists
+ $result = @$this->_memcache->set($id, array($data, time(), $lifetime), $flag, $lifetime);
+
if (count($tags) > 0) {
- $this->_log("Zend_Cache_Backend_Memcached::save() : tags are unsupported by the Memcached backend");
+ $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_MEMCACHED_BACKEND);
}
+
return $result;
}