1 | <?php |
||
10 | abstract class AdapterFileAbstract 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|null $cacheDir |
||
37 | */ |
||
38 | public function __construct($cacheDir = null) |
||
52 | |||
53 | /** |
||
54 | * Recursively creates & chmod directories. |
||
55 | * |
||
56 | * @param string $path |
||
57 | * |
||
58 | * @return bool |
||
59 | */ |
||
60 | protected function createCacheDirectory($path): bool |
||
106 | |||
107 | /** |
||
108 | * @param $cacheFile |
||
109 | * |
||
110 | * @return bool |
||
111 | */ |
||
112 | protected function deleteFile($cacheFile): bool |
||
120 | |||
121 | /** |
||
122 | * @inheritdoc |
||
123 | */ |
||
124 | public function exists(string $key): bool |
||
130 | |||
131 | /** |
||
132 | * @inheritdoc |
||
133 | */ |
||
134 | abstract public function get(string $key); |
||
135 | |||
136 | /** |
||
137 | * @inheritdoc |
||
138 | */ |
||
139 | public function installed(): bool |
||
143 | |||
144 | /** |
||
145 | * @inheritdoc |
||
146 | */ |
||
147 | public function remove(string $key): bool |
||
153 | |||
154 | /** |
||
155 | * @inheritdoc |
||
156 | */ |
||
157 | public function removeAll(): bool |
||
172 | |||
173 | /** |
||
174 | * @inheritdoc |
||
175 | */ |
||
176 | public function set(string $key, $value): bool |
||
180 | |||
181 | /** |
||
182 | * @inheritdoc |
||
183 | */ |
||
184 | abstract public function setExpired(string $key, $value, int $ttl = 0): bool; |
||
185 | |||
186 | /** |
||
187 | * @param string $key |
||
188 | * |
||
189 | * @return string |
||
190 | */ |
||
191 | protected function getFileName(string $key): string |
||
195 | |||
196 | /** |
||
197 | * Set the file-mode for new cache-files. |
||
198 | * |
||
199 | * e.g. '0777', or '0755' ... |
||
200 | * |
||
201 | * @param $fileMode |
||
202 | */ |
||
203 | public function setFileMode($fileMode) |
||
207 | |||
208 | /** |
||
209 | * @param $ttl |
||
210 | * |
||
211 | * @return bool |
||
212 | */ |
||
213 | protected function ttlHasExpired(int $ttl): bool |
||
221 | |||
222 | /** |
||
223 | * @param mixed $data |
||
224 | * |
||
225 | * @return bool |
||
226 | */ |
||
227 | protected function validateDataFromCache($data): bool |
||
241 | } |
||
242 |
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: