1 | <?php |
||
20 | class CachePathManager |
||
21 | { |
||
22 | /** |
||
23 | * Name of the file with cache paths |
||
24 | */ |
||
25 | const CACHE_FILE_NAME = '/_transformation.cache'; |
||
26 | |||
27 | /** |
||
28 | * Name of the file with class maps |
||
29 | */ |
||
30 | const CACHE_MAP_FILE_NAME = '/_classmap.cache'; |
||
31 | |||
32 | /** |
||
33 | * @var array |
||
34 | */ |
||
35 | protected $options = []; |
||
36 | |||
37 | /** |
||
38 | * @var \Go\Core\AspectKernel |
||
39 | */ |
||
40 | protected $kernel; |
||
41 | |||
42 | /** |
||
43 | * @var string|null |
||
44 | */ |
||
45 | protected $cacheDir; |
||
46 | |||
47 | /** |
||
48 | * File mode |
||
49 | * |
||
50 | * @var integer |
||
51 | */ |
||
52 | protected $fileMode; |
||
53 | |||
54 | /** |
||
55 | * @var string|null |
||
56 | */ |
||
57 | protected $appDir; |
||
58 | |||
59 | /** |
||
60 | * Cached metadata for transformation state for the concrete file |
||
61 | * |
||
62 | * @var array |
||
63 | */ |
||
64 | protected $cacheState = []; |
||
65 | |||
66 | /** |
||
67 | * New metadata items, that was not present in $cacheState |
||
68 | * |
||
69 | * @var array |
||
70 | */ |
||
71 | protected $newCacheState = []; |
||
72 | |||
73 | /** |
||
74 | * Map of classes to the filenames |
||
75 | * |
||
76 | * @var array |
||
77 | */ |
||
78 | protected $classMap = []; |
||
79 | |||
80 | /** |
||
81 | * New classmap items, that was not present in $classMap |
||
82 | * |
||
83 | * @var array |
||
84 | */ |
||
85 | protected $newClassMap = []; |
||
86 | |||
87 | 8 | public function __construct(AspectKernel $kernel) |
|
117 | |||
118 | /** |
||
119 | * Returns current cache directory for aspects, can be bull |
||
120 | * |
||
121 | * @return null|string |
||
122 | */ |
||
123 | 7 | public function getCacheDir() |
|
127 | |||
128 | /** |
||
129 | * Configures a new cache directory for aspects |
||
130 | * |
||
131 | * @param string $cacheDir New cache directory |
||
132 | */ |
||
133 | public function setCacheDir(string $cacheDir) |
||
137 | |||
138 | /** |
||
139 | * @param string $resource |
||
140 | * @return bool|string |
||
141 | */ |
||
142 | 5 | public function getCachePathForResource(string $resource) |
|
150 | |||
151 | /** |
||
152 | * Tries to return an information for queried resource |
||
153 | * |
||
154 | * @param string|null $resource Name of the file or null to get all information |
||
155 | * |
||
156 | * @return array|null Information or null if no record in the cache |
||
157 | */ |
||
158 | public function &queryCacheState(string $resource = null) |
||
171 | |||
172 | /** |
||
173 | * Returns an information about class mapping |
||
174 | */ |
||
175 | public function &queryClassMap(): array |
||
181 | |||
182 | /** |
||
183 | * Put a record about some resource in the cache |
||
184 | * |
||
185 | * This data will be persisted during object destruction |
||
186 | * |
||
187 | * @param string $resource Name of the file |
||
188 | * @param array $metadata Miscellaneous information about resource |
||
189 | */ |
||
190 | public function setCacheState(string $resource, array $metadata) |
||
195 | |||
196 | /** |
||
197 | * Put a mapping for the class |
||
198 | * |
||
199 | * This data will be persisted during object destruction |
||
200 | * |
||
201 | * @param string $class Name of the class |
||
202 | * @param array $classFileName Miscellaneous information about resource |
||
203 | */ |
||
204 | 5 | public function addClassMap(string $class, $classFileName) |
|
209 | |||
210 | /** |
||
211 | * Automatic destructor saves all new changes into the cache |
||
212 | * |
||
213 | * This implementation is not thread-safe, so be care |
||
214 | */ |
||
215 | public function __destruct() |
||
219 | |||
220 | /** |
||
221 | * Flushes the cache state into the file |
||
222 | * |
||
223 | * @var bool $force Should be flushed regardless of its state. |
||
224 | */ |
||
225 | public function flushCacheState($force = false) |
||
266 | |||
267 | /** |
||
268 | * Clear the cache state. |
||
269 | */ |
||
270 | public function clearCacheState() |
||
277 | } |
||
278 |
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: