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 | * @param string $cacheDir |
||
32 | */ |
||
33 | 6 | public function __construct($cacheDir = null) |
|
47 | |||
48 | /** |
||
49 | * @param string $key |
||
50 | * |
||
51 | * @param $key |
||
52 | * |
||
53 | * @return bool |
||
54 | */ |
||
55 | public function remove($key) |
||
61 | |||
62 | /** |
||
63 | * @param string $key |
||
64 | * |
||
65 | * @return mixed |
||
66 | */ |
||
67 | 4 | public function get($key) |
|
89 | |||
90 | /** |
||
91 | * @param $data |
||
92 | * |
||
93 | * @return bool |
||
94 | */ |
||
95 | 4 | protected function validateDataFromCache($data) |
|
109 | |||
110 | /** |
||
111 | * @param string $key |
||
112 | * |
||
113 | * @return bool |
||
114 | */ |
||
115 | 1 | public function exists($key) |
|
119 | |||
120 | /** |
||
121 | * @param string $key |
||
122 | * @param mixed $value |
||
123 | * |
||
124 | * @return bool |
||
125 | */ |
||
126 | 2 | public function set($key, $value) |
|
130 | |||
131 | /** |
||
132 | * @param string $key |
||
133 | * @param mixed $value |
||
134 | * @param int $ttl |
||
135 | * |
||
136 | * @return bool |
||
137 | */ |
||
138 | 3 | public function setExpired($key, $value, $ttl = 0) |
|
153 | |||
154 | 6 | protected function createCacheDirectory($path) |
|
166 | |||
167 | /** |
||
168 | * @param $cacheFile |
||
169 | * |
||
170 | * @return bool |
||
171 | */ |
||
172 | protected function deleteFile($cacheFile) |
||
180 | |||
181 | /** |
||
182 | * @param string $key |
||
183 | * |
||
184 | * @return string |
||
185 | */ |
||
186 | 5 | protected function getFileName($key) |
|
190 | |||
191 | /** |
||
192 | * @param $ttl |
||
193 | * |
||
194 | * @return bool |
||
195 | */ |
||
196 | 4 | protected function ttlHasExpired($ttl) |
|
204 | |||
205 | /** |
||
206 | * check if cache is installed |
||
207 | * |
||
208 | * @return boolean |
||
209 | */ |
||
210 | public function installed() |
||
214 | } |
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: