Backend.php
4.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?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 Backend
* @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* @package Zend_Cache
* @subpackage Backend
* @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Cache_Backend
{
// ------------------
// --- Properties ---
// ------------------
/**
* Frontend or Core directives
*
* =====> (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
);
/**
* Available options
*
* @var array available options
*/
protected $_options = array();
// ----------------------
// --- Public methods ---
// ----------------------
/**
* Constructor
*
* @param array $options associative array of options
*/
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
*/
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");
}
if (array_key_exists($name, $this->_directives)) {
$this->_directives[$name] = $value;
}
// specific test for the logging directive
if ($name == 'logging') {
if ((!class_exists('Zend_Log', false)) && ($value)) {
Zend_Cache::throwException('logging feature is on but Zend_Log is not "loaded"');
}
}
}
}
/**
* Set an option
*
* @param string $name
* @param mixed $value
*/
public function setOption($name, $value)
{
if (!is_string($name) || !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
*
* @return int cache life time
*/
public function getLifetime($specificLifetime)
{
if ($specificLifetime === false) {
return $this->_directives['lifetime'];
}
return $specificLifetime;
}
/**
* 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';
}
}
}