]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - inc/3rdparty/libraries/Zend/Cache/Backend.php
803fd446de3f73eea96e240c52b3feae3d396634
7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
17 * @subpackage Zend_Cache_Backend
18 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
20 * @version $Id: Backend.php 24989 2012-06-21 07:24:13Z mabe $
26 * @subpackage Zend_Cache_Backend
27 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
28 * @license http://framework.zend.com/license/new-bsd New BSD License
30 class Zend_Cache_Backend
33 * Frontend or Core directives
35 * =====> (int) lifetime :
36 * - Cache lifetime (in seconds)
37 * - If null, the cache is valid forever
39 * =====> (int) logging :
40 * - if set to true, a logging is activated throw Zend_Log
42 * @var array directives
44 protected $_directives = array(
53 * @var array available options
55 protected $_options = array();
60 * @param array $options Associative array of options
61 * @throws Zend_Cache_Exception
64 public function __construct(array $options = array())
66 while (list($name, $value) = each($options)) {
67 $this->setOption($name, $value);
72 * Set the frontend directives
74 * @param array $directives Assoc of directives
75 * @throws Zend_Cache_Exception
78 public function setDirectives($directives)
80 if (!is_array($directives)) Zend_Cache
::throwException('Directives parameter must be an array');
81 while (list($name, $value) = each($directives)) {
82 if (!is_string($name)) {
83 Zend_Cache
::throwException("Incorrect option name : $name");
85 $name = strtolower($name);
86 if (array_key_exists($name, $this->_directives)) {
87 $this->_directives[$name] = $value;
92 $this->_loggerSanity();
100 * @throws Zend_Cache_Exception
103 public function setOption($name, $value)
105 if (!is_string($name)) {
106 Zend_Cache::throwException("Incorrect option name
: $name");
108 $name = strtolower($name);
109 if (array_key_exists($name, $this->_options
)) {
110 $this->_options
[$name] = $value;
117 * @param string $name Optional, the options name to return
118 * @throws Zend_Cache_Exceptions
121 public function getOption($name)
123 $name = strtolower($name);
125 if (array_key_exists($name, $this->_options
)) {
126 return $this->_options
[$name];
129 if (array_key_exists($name, $this->_directives
)) {
130 return $this->_directives
[$name];
133 Zend_Cache
::throwException("Incorrect option name : {$name}");
139 * if $specificLifetime is not false, the given specific life time is used
140 * else, the global lifetime is used
142 * @param int $specificLifetime
143 * @return int Cache life time
145 public function getLifetime($specificLifetime)
147 if ($specificLifetime === false) {
148 return $this->_directives
['lifetime'];
150 return $specificLifetime;
154 * Return true if the automatic cleaning is available for the backend
156 * DEPRECATED : use getCapabilities() instead
161 public function isAutomaticCleaningAvailable()
167 * Determine system TMP directory and detect if we have read access
169 * inspired from Zend_File_Transfer_Adapter_Abstract
172 * @throws Zend_Cache_Exception if unable to determine directory
174 public function getTmpDir()
177 foreach (array($_ENV, $_SERVER) as $tab) {
178 foreach (array('TMPDIR', 'TEMP', 'TMP', 'windir', 'SystemRoot') as $key) {
179 if (isset($tab[$key]) && is_string($tab[$key])) {
180 if (($key == 'windir') or ($key == 'SystemRoot')) {
181 $dir = realpath($tab[$key] . '\\temp');
183 $dir = realpath($tab[$key]);
185 if ($this->_isGoodTmpDir($dir)) {
191 $upload = ini_get('upload_tmp_dir');
193 $dir = realpath($upload);
194 if ($this->_isGoodTmpDir($dir)) {
198 if (function_exists('sys_get_temp_dir')) {
199 $dir = sys_get_temp_dir();
200 if ($this->_isGoodTmpDir($dir)) {
204 // Attemp to detect by creating a temporary file
205 $tempFile = tempnam(md5(uniqid(rand(), TRUE)), '');
207 $dir = realpath(dirname($tempFile));
209 if ($this->_isGoodTmpDir($dir)) {
213 if ($this->_isGoodTmpDir('/tmp')) {
216 if ($this->_isGoodTmpDir('\\temp')) {
219 Zend_Cache
::throwException('Could not determine temp directory, please specify a cache_dir manually');
223 * Verify if the given temporary directory is readable and writable
225 * @param string $dir temporary directory
226 * @return boolean true if the directory is ok
228 protected function _isGoodTmpDir($dir)
230 if (is_readable($dir)) {
231 if (is_writable($dir)) {
239 * Make sure if we enable logging that the Zend_Log class
241 * Create a default log object if none is set.
243 * @throws Zend_Cache_Exception
246 protected function _loggerSanity()
248 if (!isset($this->_directives
['logging']) || !$this->_directives
['logging']) {
252 if (isset($this->_directives
['logger'])) {
253 if ($this->_directives
['logger'] instanceof Zend_Log
) {
256 Zend_Cache
::throwException('Logger object is not an instance of Zend_Log class.');
259 // Create a default logger to the standard output stream
260 require_once 'Zend/Log.php';
261 require_once 'Zend/Log/Writer/Stream.php';
262 require_once 'Zend/Log/Filter/Priority.php';
263 $logger = new Zend_Log(new Zend_Log_Writer_Stream('php://output'));
264 $logger->addFilter(new Zend_Log_Filter_Priority(Zend_Log
::WARN
, '<='));
265 $this->_directives
['logger'] = $logger;
269 * Log a message at the WARN (4) priority.
271 * @param string $message
272 * @throws Zend_Cache_Exception
275 protected function _log($message, $priority = 4)
277 if (!$this->_directives
['logging']) {
281 if (!isset($this->_directives
['logger'])) {
282 Zend_Cache
::throwException('Logging is enabled but logger is not set.');
284 $logger = $this->_directives
['logger'];
285 if (!$logger instanceof Zend_Log
) {
286 Zend_Cache
::throwException('Logger object is not an instance of Zend_Log class.');
288 $logger->log($message, $priority);