1 | <?php |
||
10 | class AdapterFile implements iAdapter |
||
11 | { |
||
12 | const CACHE_FILE_PREFIX = '__'; |
||
13 | const CACHE_FILE_SUBFIX = '.php.cache'; |
||
14 | |||
15 | /** |
||
16 | * @var bool |
||
17 | */ |
||
18 | public $installed = false; |
||
19 | |||
20 | /** |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $cacheDir; |
||
24 | |||
25 | /** |
||
26 | * @var iSerializer |
||
27 | */ |
||
28 | protected $serializer; |
||
29 | |||
30 | /** |
||
31 | * @var string |
||
32 | */ |
||
33 | protected $fileMode = '0755'; |
||
34 | |||
35 | /** |
||
36 | * @param string $cacheDir |
||
37 | */ |
||
38 | 6 | public function __construct($cacheDir = null) |
|
52 | |||
53 | /** |
||
54 | * @param string $key |
||
55 | * |
||
56 | * @param $key |
||
57 | * |
||
58 | * @return bool |
||
59 | */ |
||
60 | public function remove($key) |
||
66 | |||
67 | /** |
||
68 | * @param string $key |
||
69 | * |
||
70 | * @return mixed |
||
71 | */ |
||
72 | 4 | public function get($key) |
|
94 | |||
95 | /** |
||
96 | * @param $data |
||
97 | * |
||
98 | * @return bool |
||
99 | */ |
||
100 | 4 | protected function validateDataFromCache($data) |
|
114 | |||
115 | /** |
||
116 | * @param string $key |
||
117 | * |
||
118 | * @return bool |
||
119 | */ |
||
120 | 1 | public function exists($key) |
|
124 | |||
125 | /** |
||
126 | * @param string $key |
||
127 | * @param mixed $value |
||
128 | * |
||
129 | * @return bool |
||
130 | */ |
||
131 | 2 | public function set($key, $value) |
|
135 | |||
136 | /** |
||
137 | * @param string $key |
||
138 | * @param mixed $value |
||
139 | * @param int $ttl |
||
140 | * |
||
141 | * @return bool |
||
142 | */ |
||
143 | 3 | public function setExpired($key, $value, $ttl = 0) |
|
158 | |||
159 | /** |
||
160 | * recursively creates & chmod directories |
||
161 | * |
||
162 | * @param string $path |
||
163 | * |
||
164 | * @return bool |
||
165 | */ |
||
166 | 6 | protected function createCacheDirectory($path) |
|
211 | |||
212 | /** |
||
213 | * @param $cacheFile |
||
214 | * |
||
215 | * @return bool |
||
216 | */ |
||
217 | protected function deleteFile($cacheFile) |
||
225 | |||
226 | /** |
||
227 | * @param string $key |
||
228 | * |
||
229 | * @return string |
||
230 | */ |
||
231 | 5 | protected function getFileName($key) |
|
235 | |||
236 | /** |
||
237 | * @param $ttl |
||
238 | * |
||
239 | * @return bool |
||
240 | */ |
||
241 | 4 | protected function ttlHasExpired($ttl) |
|
249 | |||
250 | /** |
||
251 | * e.g. '0777', or '0755' ... |
||
252 | * |
||
253 | * @param $fileMode |
||
254 | */ |
||
255 | public function setFileMode($fileMode) |
||
259 | |||
260 | /** |
||
261 | * check if cache is installed |
||
262 | * |
||
263 | * @return boolean |
||
264 | */ |
||
265 | public function installed() |
||
269 | } |
||
270 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: