@@ -22,114 +22,114 @@ |
||
22 | 22 | |
23 | 23 | trait IOConfigurationOptionTrait |
24 | 24 | { |
25 | - /** |
|
26 | - * @var boolean |
|
27 | - */ |
|
28 | - protected $secureFileManipulation = false; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var bool |
|
32 | - */ |
|
33 | - protected $htaccess = true; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var string |
|
37 | - */ |
|
38 | - protected $securityKey = ''; |
|
39 | - |
|
40 | - /** |
|
41 | - * @var string |
|
42 | - */ |
|
43 | - protected $cacheFileExtension = 'txt'; |
|
44 | - |
|
45 | - /** |
|
46 | - * @return string |
|
47 | - */ |
|
48 | - public function getSecurityKey(): string |
|
49 | - { |
|
50 | - return $this->securityKey; |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * @param string $securityKey |
|
55 | - * @return Config |
|
56 | - */ |
|
57 | - public function setSecurityKey(string $securityKey): self |
|
58 | - { |
|
59 | - $this->securityKey = $securityKey; |
|
60 | - |
|
61 | - return $this; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * @return bool |
|
66 | - */ |
|
67 | - public function getHtaccess(): bool |
|
68 | - { |
|
69 | - return $this->htaccess; |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * @param bool $htaccess |
|
74 | - * @return Config |
|
75 | - */ |
|
76 | - public function setHtaccess(bool $htaccess): ConfigurationOptionInterface |
|
77 | - { |
|
78 | - $this->htaccess = $htaccess; |
|
79 | - |
|
80 | - return $this; |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * @return bool |
|
85 | - */ |
|
86 | - public function isSecureFileManipulation(): bool |
|
87 | - { |
|
88 | - return $this->secureFileManipulation; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * @param bool $secureFileManipulation |
|
93 | - * @return self |
|
94 | - */ |
|
95 | - public function setSecureFileManipulation(bool $secureFileManipulation): self |
|
96 | - { |
|
97 | - $this->secureFileManipulation = $secureFileManipulation; |
|
98 | - return $this; |
|
99 | - } |
|
100 | - |
|
101 | - |
|
102 | - /** |
|
103 | - * @return string |
|
104 | - */ |
|
105 | - public function getCacheFileExtension(): string |
|
106 | - { |
|
107 | - return $this->cacheFileExtension; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * @param string $cacheFileExtension |
|
112 | - * @return self |
|
113 | - * @throws PhpfastcacheInvalidConfigurationException |
|
114 | - */ |
|
115 | - public function setCacheFileExtension(string $cacheFileExtension): self |
|
116 | - { |
|
117 | - /** |
|
118 | - * Feel free to propose your own one |
|
119 | - * by opening a pull request :) |
|
120 | - */ |
|
121 | - $safeFileExtensions = \explode('|', SAFE_FILE_EXTENSIONS); |
|
122 | - |
|
123 | - if (\strpos($cacheFileExtension, '.') !== false) { |
|
124 | - throw new PhpfastcacheInvalidConfigurationException('cacheFileExtension cannot contain a dot "."'); |
|
125 | - } |
|
126 | - if (!\in_array($cacheFileExtension, $safeFileExtensions, true)) { |
|
127 | - throw new PhpfastcacheInvalidConfigurationException( |
|
128 | - "Extension \"{$cacheFileExtension}\" is not safe, currently allowed extension names: " . \implode(', ', $safeFileExtensions) |
|
129 | - ); |
|
130 | - } |
|
131 | - |
|
132 | - $this->cacheFileExtension = $cacheFileExtension; |
|
133 | - return $this; |
|
134 | - } |
|
25 | + /** |
|
26 | + * @var boolean |
|
27 | + */ |
|
28 | + protected $secureFileManipulation = false; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var bool |
|
32 | + */ |
|
33 | + protected $htaccess = true; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var string |
|
37 | + */ |
|
38 | + protected $securityKey = ''; |
|
39 | + |
|
40 | + /** |
|
41 | + * @var string |
|
42 | + */ |
|
43 | + protected $cacheFileExtension = 'txt'; |
|
44 | + |
|
45 | + /** |
|
46 | + * @return string |
|
47 | + */ |
|
48 | + public function getSecurityKey(): string |
|
49 | + { |
|
50 | + return $this->securityKey; |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * @param string $securityKey |
|
55 | + * @return Config |
|
56 | + */ |
|
57 | + public function setSecurityKey(string $securityKey): self |
|
58 | + { |
|
59 | + $this->securityKey = $securityKey; |
|
60 | + |
|
61 | + return $this; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * @return bool |
|
66 | + */ |
|
67 | + public function getHtaccess(): bool |
|
68 | + { |
|
69 | + return $this->htaccess; |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * @param bool $htaccess |
|
74 | + * @return Config |
|
75 | + */ |
|
76 | + public function setHtaccess(bool $htaccess): ConfigurationOptionInterface |
|
77 | + { |
|
78 | + $this->htaccess = $htaccess; |
|
79 | + |
|
80 | + return $this; |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * @return bool |
|
85 | + */ |
|
86 | + public function isSecureFileManipulation(): bool |
|
87 | + { |
|
88 | + return $this->secureFileManipulation; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * @param bool $secureFileManipulation |
|
93 | + * @return self |
|
94 | + */ |
|
95 | + public function setSecureFileManipulation(bool $secureFileManipulation): self |
|
96 | + { |
|
97 | + $this->secureFileManipulation = $secureFileManipulation; |
|
98 | + return $this; |
|
99 | + } |
|
100 | + |
|
101 | + |
|
102 | + /** |
|
103 | + * @return string |
|
104 | + */ |
|
105 | + public function getCacheFileExtension(): string |
|
106 | + { |
|
107 | + return $this->cacheFileExtension; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * @param string $cacheFileExtension |
|
112 | + * @return self |
|
113 | + * @throws PhpfastcacheInvalidConfigurationException |
|
114 | + */ |
|
115 | + public function setCacheFileExtension(string $cacheFileExtension): self |
|
116 | + { |
|
117 | + /** |
|
118 | + * Feel free to propose your own one |
|
119 | + * by opening a pull request :) |
|
120 | + */ |
|
121 | + $safeFileExtensions = \explode('|', SAFE_FILE_EXTENSIONS); |
|
122 | + |
|
123 | + if (\strpos($cacheFileExtension, '.') !== false) { |
|
124 | + throw new PhpfastcacheInvalidConfigurationException('cacheFileExtension cannot contain a dot "."'); |
|
125 | + } |
|
126 | + if (!\in_array($cacheFileExtension, $safeFileExtensions, true)) { |
|
127 | + throw new PhpfastcacheInvalidConfigurationException( |
|
128 | + "Extension \"{$cacheFileExtension}\" is not safe, currently allowed extension names: " . \implode(', ', $safeFileExtensions) |
|
129 | + ); |
|
130 | + } |
|
131 | + |
|
132 | + $this->cacheFileExtension = $cacheFileExtension; |
|
133 | + return $this; |
|
134 | + } |
|
135 | 135 | } |
136 | 136 | \ No newline at end of file |
@@ -29,361 +29,361 @@ |
||
29 | 29 | */ |
30 | 30 | class ConfigurationOption extends ArrayObject implements ConfigurationOptionInterface |
31 | 31 | { |
32 | - /** |
|
33 | - * @var bool |
|
34 | - */ |
|
35 | - protected $itemDetailedDate = false; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var bool |
|
39 | - */ |
|
40 | - protected $autoTmpFallback = false; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var int |
|
44 | - */ |
|
45 | - protected $defaultTtl = 900; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var string|Callable |
|
49 | - */ |
|
50 | - protected $defaultKeyHashFunction = 'md5'; |
|
51 | - |
|
52 | - /** |
|
53 | - * @var string|Callable |
|
54 | - */ |
|
55 | - protected $defaultFileNameHashFunction = 'md5'; |
|
56 | - |
|
57 | - /** |
|
58 | - * @var int |
|
59 | - */ |
|
60 | - protected $defaultChmod = 0777; |
|
61 | - |
|
62 | - /** |
|
63 | - * @var string |
|
64 | - */ |
|
65 | - protected $path = ''; |
|
66 | - |
|
67 | - /** |
|
68 | - * @var int |
|
69 | - */ |
|
70 | - protected $limitedMemoryByObject = 4096; |
|
71 | - |
|
72 | - /** |
|
73 | - * @var bool |
|
74 | - */ |
|
75 | - protected $compressData = false; |
|
76 | - |
|
77 | - /** |
|
78 | - * @var bool |
|
79 | - */ |
|
80 | - protected $preventCacheSlams = false; |
|
81 | - |
|
82 | - /** |
|
83 | - * @var int |
|
84 | - */ |
|
85 | - protected $cacheSlamsTimeout = 15; |
|
86 | - |
|
87 | - /** |
|
88 | - * @var bool |
|
89 | - */ |
|
90 | - protected $useStaticItemCaching = true; |
|
91 | - |
|
92 | - /** |
|
93 | - * @param $args |
|
94 | - * ArrayObject constructor. |
|
95 | - * @throws PhpfastcacheInvalidConfigurationException |
|
96 | - * @throws ReflectionException |
|
97 | - */ |
|
98 | - public function __construct(...$args) |
|
99 | - { |
|
100 | - parent::__construct(...$args); |
|
101 | - $array =& $this->getArray(); |
|
102 | - |
|
103 | - /** |
|
104 | - * Detect unwanted keys and throw an exception. |
|
105 | - * No more kidding now, it's 21th century. |
|
106 | - */ |
|
107 | - if (\array_diff_key($array, \get_object_vars($this))) { |
|
108 | - throw new PhpfastcacheInvalidConfigurationException( |
|
109 | - sprintf( |
|
110 | - 'Invalid option(s) for the config %s: %s', |
|
111 | - static::class, |
|
112 | - \implode(', ', \array_keys(\array_diff_key($array, \get_object_vars($this)))) |
|
113 | - ) |
|
114 | - ); |
|
115 | - } |
|
116 | - |
|
117 | - foreach (\get_object_vars($this) as $property => $value) { |
|
118 | - if (\array_key_exists($property, $array)) { |
|
119 | - $this->$property = &$array[$property]; |
|
120 | - } else { |
|
121 | - $array[$property] = &$this->$property; |
|
122 | - } |
|
123 | - } |
|
124 | - |
|
125 | - foreach (\get_class_methods($this) as $method) { |
|
126 | - if (\strpos($method, 'set') === 0) { |
|
127 | - $value = null; |
|
128 | - try { |
|
129 | - /** |
|
130 | - * We use property instead of getter |
|
131 | - * because of is/get conditions and |
|
132 | - * to allow us to retrieve the value |
|
133 | - * in catch statement block |
|
134 | - */ |
|
135 | - $value = $this->{\lcfirst(\substr($method, 3))}; |
|
136 | - $this->{$method}($value); |
|
137 | - } catch (TypeError $e) { |
|
138 | - $typeHintGot = \is_object($value) ? \get_class($value) : \gettype($value); |
|
139 | - $reflectionMethod = new ReflectionMethod($this, $method); |
|
140 | - $parameter = $reflectionMethod->getParameters()[0] ?? null; |
|
141 | - $typeHintExpected = ($parameter instanceof ReflectionParameter ? ($parameter->getType()->getName() === 'object' ? $parameter->getClass() : $parameter->getType( |
|
142 | - )->getName()) : 'Unknown type'); |
|
143 | - |
|
144 | - throw new PhpfastcacheInvalidConfigurationException( |
|
145 | - \sprintf( |
|
146 | - 'Invalid type hint found for "%s", expected "%s" got "%s"', |
|
147 | - \lcfirst(\substr($method, 3)), |
|
148 | - $typeHintExpected, |
|
149 | - $typeHintGot |
|
150 | - ) |
|
151 | - ); |
|
152 | - } |
|
153 | - } |
|
154 | - } |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * @param string $optionName |
|
159 | - * @return mixed|null |
|
160 | - */ |
|
161 | - public function isValidOption(string $optionName) |
|
162 | - { |
|
163 | - return property_exists($this, $optionName); |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * @return bool |
|
168 | - */ |
|
169 | - public function isItemDetailedDate(): bool |
|
170 | - { |
|
171 | - return $this->itemDetailedDate; |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * @param bool $itemDetailedDate |
|
176 | - * @return ConfigurationOption |
|
177 | - */ |
|
178 | - public function setItemDetailedDate(bool $itemDetailedDate): self |
|
179 | - { |
|
180 | - $this->itemDetailedDate = $itemDetailedDate; |
|
181 | - return $this; |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * @return bool |
|
186 | - */ |
|
187 | - public function isAutoTmpFallback(): bool |
|
188 | - { |
|
189 | - return $this->autoTmpFallback; |
|
190 | - } |
|
191 | - |
|
192 | - /** |
|
193 | - * @param bool $autoTmpFallback |
|
194 | - * @return ConfigurationOption |
|
195 | - */ |
|
196 | - public function setAutoTmpFallback(bool $autoTmpFallback): self |
|
197 | - { |
|
198 | - $this->autoTmpFallback = $autoTmpFallback; |
|
199 | - return $this; |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * @return int |
|
204 | - */ |
|
205 | - public function getDefaultTtl(): int |
|
206 | - { |
|
207 | - return $this->defaultTtl; |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * @param int $defaultTtl |
|
212 | - * @return ConfigurationOption |
|
213 | - */ |
|
214 | - public function setDefaultTtl(int $defaultTtl): self |
|
215 | - { |
|
216 | - $this->defaultTtl = $defaultTtl; |
|
217 | - return $this; |
|
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * @return Callable|string |
|
222 | - */ |
|
223 | - public function getDefaultKeyHashFunction() |
|
224 | - { |
|
225 | - return $this->defaultKeyHashFunction; |
|
226 | - } |
|
227 | - |
|
228 | - /** |
|
229 | - * @param Callable|string $defaultKeyHashFunction |
|
230 | - * @return ConfigurationOption |
|
231 | - * @throws PhpfastcacheInvalidConfigurationException |
|
232 | - */ |
|
233 | - public function setDefaultKeyHashFunction($defaultKeyHashFunction): self |
|
234 | - { |
|
235 | - if ($defaultKeyHashFunction && !\is_callable($defaultKeyHashFunction) && (\is_string($defaultKeyHashFunction) && !\function_exists($defaultKeyHashFunction))) { |
|
236 | - throw new PhpfastcacheInvalidConfigurationException('defaultKeyHashFunction must be a valid function name string'); |
|
237 | - } |
|
238 | - $this->defaultKeyHashFunction = $defaultKeyHashFunction; |
|
239 | - return $this; |
|
240 | - } |
|
241 | - |
|
242 | - /** |
|
243 | - * @return Callable|string |
|
244 | - */ |
|
245 | - public function getDefaultFileNameHashFunction() |
|
246 | - { |
|
247 | - return $this->defaultFileNameHashFunction; |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * @param Callable|string $defaultFileNameHashFunction |
|
252 | - * @return ConfigurationOption |
|
253 | - * @throws PhpfastcacheInvalidConfigurationException |
|
254 | - */ |
|
255 | - public function setDefaultFileNameHashFunction($defaultFileNameHashFunction): self |
|
256 | - { |
|
257 | - if (!\is_callable($defaultFileNameHashFunction) && (\is_string($defaultFileNameHashFunction) && !\function_exists($defaultFileNameHashFunction))) { |
|
258 | - throw new PhpfastcacheInvalidConfigurationException('defaultFileNameHashFunction must be a valid function name string'); |
|
259 | - } |
|
260 | - $this->defaultFileNameHashFunction = $defaultFileNameHashFunction; |
|
261 | - return $this; |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * @return int |
|
266 | - */ |
|
267 | - public function getDefaultChmod(): int |
|
268 | - { |
|
269 | - return $this->defaultChmod; |
|
270 | - } |
|
271 | - |
|
272 | - /** |
|
273 | - * @param int $defaultChmod |
|
274 | - * @return ConfigurationOption |
|
275 | - */ |
|
276 | - public function setDefaultChmod(int $defaultChmod): self |
|
277 | - { |
|
278 | - $this->defaultChmod = $defaultChmod; |
|
279 | - return $this; |
|
280 | - } |
|
281 | - |
|
282 | - /** |
|
283 | - * @return string |
|
284 | - */ |
|
285 | - public function getPath(): string |
|
286 | - { |
|
287 | - return $this->path; |
|
288 | - } |
|
289 | - |
|
290 | - /** |
|
291 | - * @param string $path |
|
292 | - * @return ConfigurationOption |
|
293 | - */ |
|
294 | - public function setPath(string $path): self |
|
295 | - { |
|
296 | - $this->path = $path; |
|
297 | - return $this; |
|
298 | - } |
|
299 | - |
|
300 | - /** |
|
301 | - * @return int |
|
302 | - */ |
|
303 | - public function getLimitedMemoryByObject(): int |
|
304 | - { |
|
305 | - return $this->limitedMemoryByObject; |
|
306 | - } |
|
307 | - |
|
308 | - /** |
|
309 | - * @param int $limitedMemoryByObject |
|
310 | - * @return ConfigurationOption |
|
311 | - */ |
|
312 | - public function setLimitedMemoryByObject(int $limitedMemoryByObject): self |
|
313 | - { |
|
314 | - $this->limitedMemoryByObject = $limitedMemoryByObject; |
|
315 | - return $this; |
|
316 | - } |
|
317 | - |
|
318 | - /** |
|
319 | - * @return bool |
|
320 | - */ |
|
321 | - public function isCompressData(): bool |
|
322 | - { |
|
323 | - return $this->compressData; |
|
324 | - } |
|
325 | - |
|
326 | - /** |
|
327 | - * @param bool $compressData |
|
328 | - * @return ConfigurationOption |
|
329 | - */ |
|
330 | - public function setCompressData(bool $compressData): self |
|
331 | - { |
|
332 | - $this->compressData = $compressData; |
|
333 | - return $this; |
|
334 | - } |
|
335 | - |
|
336 | - /** |
|
337 | - * @return bool |
|
338 | - */ |
|
339 | - public function isPreventCacheSlams(): bool |
|
340 | - { |
|
341 | - return $this->preventCacheSlams; |
|
342 | - } |
|
343 | - |
|
344 | - /** |
|
345 | - * @param bool $preventCacheSlams |
|
346 | - * @return ConfigurationOption |
|
347 | - */ |
|
348 | - public function setPreventCacheSlams(bool $preventCacheSlams): self |
|
349 | - { |
|
350 | - $this->preventCacheSlams = $preventCacheSlams; |
|
351 | - return $this; |
|
352 | - } |
|
353 | - |
|
354 | - /** |
|
355 | - * @return int |
|
356 | - */ |
|
357 | - public function getCacheSlamsTimeout(): int |
|
358 | - { |
|
359 | - return $this->cacheSlamsTimeout; |
|
360 | - } |
|
361 | - |
|
362 | - /** |
|
363 | - * @param int $cacheSlamsTimeout |
|
364 | - * @return ConfigurationOption |
|
365 | - */ |
|
366 | - public function setCacheSlamsTimeout(int $cacheSlamsTimeout): self |
|
367 | - { |
|
368 | - $this->cacheSlamsTimeout = $cacheSlamsTimeout; |
|
369 | - return $this; |
|
370 | - } |
|
371 | - |
|
372 | - /** |
|
373 | - * @return bool |
|
374 | - */ |
|
375 | - public function isUseStaticItemCaching(): bool |
|
376 | - { |
|
377 | - return $this->useStaticItemCaching; |
|
378 | - } |
|
379 | - |
|
380 | - /** |
|
381 | - * @param bool $useStaticItemCaching |
|
382 | - * @return ConfigurationOption |
|
383 | - */ |
|
384 | - public function setUseStaticItemCaching(bool $useStaticItemCaching): self |
|
385 | - { |
|
386 | - $this->useStaticItemCaching = $useStaticItemCaching; |
|
387 | - return $this; |
|
388 | - } |
|
32 | + /** |
|
33 | + * @var bool |
|
34 | + */ |
|
35 | + protected $itemDetailedDate = false; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var bool |
|
39 | + */ |
|
40 | + protected $autoTmpFallback = false; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var int |
|
44 | + */ |
|
45 | + protected $defaultTtl = 900; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var string|Callable |
|
49 | + */ |
|
50 | + protected $defaultKeyHashFunction = 'md5'; |
|
51 | + |
|
52 | + /** |
|
53 | + * @var string|Callable |
|
54 | + */ |
|
55 | + protected $defaultFileNameHashFunction = 'md5'; |
|
56 | + |
|
57 | + /** |
|
58 | + * @var int |
|
59 | + */ |
|
60 | + protected $defaultChmod = 0777; |
|
61 | + |
|
62 | + /** |
|
63 | + * @var string |
|
64 | + */ |
|
65 | + protected $path = ''; |
|
66 | + |
|
67 | + /** |
|
68 | + * @var int |
|
69 | + */ |
|
70 | + protected $limitedMemoryByObject = 4096; |
|
71 | + |
|
72 | + /** |
|
73 | + * @var bool |
|
74 | + */ |
|
75 | + protected $compressData = false; |
|
76 | + |
|
77 | + /** |
|
78 | + * @var bool |
|
79 | + */ |
|
80 | + protected $preventCacheSlams = false; |
|
81 | + |
|
82 | + /** |
|
83 | + * @var int |
|
84 | + */ |
|
85 | + protected $cacheSlamsTimeout = 15; |
|
86 | + |
|
87 | + /** |
|
88 | + * @var bool |
|
89 | + */ |
|
90 | + protected $useStaticItemCaching = true; |
|
91 | + |
|
92 | + /** |
|
93 | + * @param $args |
|
94 | + * ArrayObject constructor. |
|
95 | + * @throws PhpfastcacheInvalidConfigurationException |
|
96 | + * @throws ReflectionException |
|
97 | + */ |
|
98 | + public function __construct(...$args) |
|
99 | + { |
|
100 | + parent::__construct(...$args); |
|
101 | + $array =& $this->getArray(); |
|
102 | + |
|
103 | + /** |
|
104 | + * Detect unwanted keys and throw an exception. |
|
105 | + * No more kidding now, it's 21th century. |
|
106 | + */ |
|
107 | + if (\array_diff_key($array, \get_object_vars($this))) { |
|
108 | + throw new PhpfastcacheInvalidConfigurationException( |
|
109 | + sprintf( |
|
110 | + 'Invalid option(s) for the config %s: %s', |
|
111 | + static::class, |
|
112 | + \implode(', ', \array_keys(\array_diff_key($array, \get_object_vars($this)))) |
|
113 | + ) |
|
114 | + ); |
|
115 | + } |
|
116 | + |
|
117 | + foreach (\get_object_vars($this) as $property => $value) { |
|
118 | + if (\array_key_exists($property, $array)) { |
|
119 | + $this->$property = &$array[$property]; |
|
120 | + } else { |
|
121 | + $array[$property] = &$this->$property; |
|
122 | + } |
|
123 | + } |
|
124 | + |
|
125 | + foreach (\get_class_methods($this) as $method) { |
|
126 | + if (\strpos($method, 'set') === 0) { |
|
127 | + $value = null; |
|
128 | + try { |
|
129 | + /** |
|
130 | + * We use property instead of getter |
|
131 | + * because of is/get conditions and |
|
132 | + * to allow us to retrieve the value |
|
133 | + * in catch statement block |
|
134 | + */ |
|
135 | + $value = $this->{\lcfirst(\substr($method, 3))}; |
|
136 | + $this->{$method}($value); |
|
137 | + } catch (TypeError $e) { |
|
138 | + $typeHintGot = \is_object($value) ? \get_class($value) : \gettype($value); |
|
139 | + $reflectionMethod = new ReflectionMethod($this, $method); |
|
140 | + $parameter = $reflectionMethod->getParameters()[0] ?? null; |
|
141 | + $typeHintExpected = ($parameter instanceof ReflectionParameter ? ($parameter->getType()->getName() === 'object' ? $parameter->getClass() : $parameter->getType( |
|
142 | + )->getName()) : 'Unknown type'); |
|
143 | + |
|
144 | + throw new PhpfastcacheInvalidConfigurationException( |
|
145 | + \sprintf( |
|
146 | + 'Invalid type hint found for "%s", expected "%s" got "%s"', |
|
147 | + \lcfirst(\substr($method, 3)), |
|
148 | + $typeHintExpected, |
|
149 | + $typeHintGot |
|
150 | + ) |
|
151 | + ); |
|
152 | + } |
|
153 | + } |
|
154 | + } |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * @param string $optionName |
|
159 | + * @return mixed|null |
|
160 | + */ |
|
161 | + public function isValidOption(string $optionName) |
|
162 | + { |
|
163 | + return property_exists($this, $optionName); |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * @return bool |
|
168 | + */ |
|
169 | + public function isItemDetailedDate(): bool |
|
170 | + { |
|
171 | + return $this->itemDetailedDate; |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * @param bool $itemDetailedDate |
|
176 | + * @return ConfigurationOption |
|
177 | + */ |
|
178 | + public function setItemDetailedDate(bool $itemDetailedDate): self |
|
179 | + { |
|
180 | + $this->itemDetailedDate = $itemDetailedDate; |
|
181 | + return $this; |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * @return bool |
|
186 | + */ |
|
187 | + public function isAutoTmpFallback(): bool |
|
188 | + { |
|
189 | + return $this->autoTmpFallback; |
|
190 | + } |
|
191 | + |
|
192 | + /** |
|
193 | + * @param bool $autoTmpFallback |
|
194 | + * @return ConfigurationOption |
|
195 | + */ |
|
196 | + public function setAutoTmpFallback(bool $autoTmpFallback): self |
|
197 | + { |
|
198 | + $this->autoTmpFallback = $autoTmpFallback; |
|
199 | + return $this; |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * @return int |
|
204 | + */ |
|
205 | + public function getDefaultTtl(): int |
|
206 | + { |
|
207 | + return $this->defaultTtl; |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * @param int $defaultTtl |
|
212 | + * @return ConfigurationOption |
|
213 | + */ |
|
214 | + public function setDefaultTtl(int $defaultTtl): self |
|
215 | + { |
|
216 | + $this->defaultTtl = $defaultTtl; |
|
217 | + return $this; |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * @return Callable|string |
|
222 | + */ |
|
223 | + public function getDefaultKeyHashFunction() |
|
224 | + { |
|
225 | + return $this->defaultKeyHashFunction; |
|
226 | + } |
|
227 | + |
|
228 | + /** |
|
229 | + * @param Callable|string $defaultKeyHashFunction |
|
230 | + * @return ConfigurationOption |
|
231 | + * @throws PhpfastcacheInvalidConfigurationException |
|
232 | + */ |
|
233 | + public function setDefaultKeyHashFunction($defaultKeyHashFunction): self |
|
234 | + { |
|
235 | + if ($defaultKeyHashFunction && !\is_callable($defaultKeyHashFunction) && (\is_string($defaultKeyHashFunction) && !\function_exists($defaultKeyHashFunction))) { |
|
236 | + throw new PhpfastcacheInvalidConfigurationException('defaultKeyHashFunction must be a valid function name string'); |
|
237 | + } |
|
238 | + $this->defaultKeyHashFunction = $defaultKeyHashFunction; |
|
239 | + return $this; |
|
240 | + } |
|
241 | + |
|
242 | + /** |
|
243 | + * @return Callable|string |
|
244 | + */ |
|
245 | + public function getDefaultFileNameHashFunction() |
|
246 | + { |
|
247 | + return $this->defaultFileNameHashFunction; |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * @param Callable|string $defaultFileNameHashFunction |
|
252 | + * @return ConfigurationOption |
|
253 | + * @throws PhpfastcacheInvalidConfigurationException |
|
254 | + */ |
|
255 | + public function setDefaultFileNameHashFunction($defaultFileNameHashFunction): self |
|
256 | + { |
|
257 | + if (!\is_callable($defaultFileNameHashFunction) && (\is_string($defaultFileNameHashFunction) && !\function_exists($defaultFileNameHashFunction))) { |
|
258 | + throw new PhpfastcacheInvalidConfigurationException('defaultFileNameHashFunction must be a valid function name string'); |
|
259 | + } |
|
260 | + $this->defaultFileNameHashFunction = $defaultFileNameHashFunction; |
|
261 | + return $this; |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * @return int |
|
266 | + */ |
|
267 | + public function getDefaultChmod(): int |
|
268 | + { |
|
269 | + return $this->defaultChmod; |
|
270 | + } |
|
271 | + |
|
272 | + /** |
|
273 | + * @param int $defaultChmod |
|
274 | + * @return ConfigurationOption |
|
275 | + */ |
|
276 | + public function setDefaultChmod(int $defaultChmod): self |
|
277 | + { |
|
278 | + $this->defaultChmod = $defaultChmod; |
|
279 | + return $this; |
|
280 | + } |
|
281 | + |
|
282 | + /** |
|
283 | + * @return string |
|
284 | + */ |
|
285 | + public function getPath(): string |
|
286 | + { |
|
287 | + return $this->path; |
|
288 | + } |
|
289 | + |
|
290 | + /** |
|
291 | + * @param string $path |
|
292 | + * @return ConfigurationOption |
|
293 | + */ |
|
294 | + public function setPath(string $path): self |
|
295 | + { |
|
296 | + $this->path = $path; |
|
297 | + return $this; |
|
298 | + } |
|
299 | + |
|
300 | + /** |
|
301 | + * @return int |
|
302 | + */ |
|
303 | + public function getLimitedMemoryByObject(): int |
|
304 | + { |
|
305 | + return $this->limitedMemoryByObject; |
|
306 | + } |
|
307 | + |
|
308 | + /** |
|
309 | + * @param int $limitedMemoryByObject |
|
310 | + * @return ConfigurationOption |
|
311 | + */ |
|
312 | + public function setLimitedMemoryByObject(int $limitedMemoryByObject): self |
|
313 | + { |
|
314 | + $this->limitedMemoryByObject = $limitedMemoryByObject; |
|
315 | + return $this; |
|
316 | + } |
|
317 | + |
|
318 | + /** |
|
319 | + * @return bool |
|
320 | + */ |
|
321 | + public function isCompressData(): bool |
|
322 | + { |
|
323 | + return $this->compressData; |
|
324 | + } |
|
325 | + |
|
326 | + /** |
|
327 | + * @param bool $compressData |
|
328 | + * @return ConfigurationOption |
|
329 | + */ |
|
330 | + public function setCompressData(bool $compressData): self |
|
331 | + { |
|
332 | + $this->compressData = $compressData; |
|
333 | + return $this; |
|
334 | + } |
|
335 | + |
|
336 | + /** |
|
337 | + * @return bool |
|
338 | + */ |
|
339 | + public function isPreventCacheSlams(): bool |
|
340 | + { |
|
341 | + return $this->preventCacheSlams; |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * @param bool $preventCacheSlams |
|
346 | + * @return ConfigurationOption |
|
347 | + */ |
|
348 | + public function setPreventCacheSlams(bool $preventCacheSlams): self |
|
349 | + { |
|
350 | + $this->preventCacheSlams = $preventCacheSlams; |
|
351 | + return $this; |
|
352 | + } |
|
353 | + |
|
354 | + /** |
|
355 | + * @return int |
|
356 | + */ |
|
357 | + public function getCacheSlamsTimeout(): int |
|
358 | + { |
|
359 | + return $this->cacheSlamsTimeout; |
|
360 | + } |
|
361 | + |
|
362 | + /** |
|
363 | + * @param int $cacheSlamsTimeout |
|
364 | + * @return ConfigurationOption |
|
365 | + */ |
|
366 | + public function setCacheSlamsTimeout(int $cacheSlamsTimeout): self |
|
367 | + { |
|
368 | + $this->cacheSlamsTimeout = $cacheSlamsTimeout; |
|
369 | + return $this; |
|
370 | + } |
|
371 | + |
|
372 | + /** |
|
373 | + * @return bool |
|
374 | + */ |
|
375 | + public function isUseStaticItemCaching(): bool |
|
376 | + { |
|
377 | + return $this->useStaticItemCaching; |
|
378 | + } |
|
379 | + |
|
380 | + /** |
|
381 | + * @param bool $useStaticItemCaching |
|
382 | + * @return ConfigurationOption |
|
383 | + */ |
|
384 | + public function setUseStaticItemCaching(bool $useStaticItemCaching): self |
|
385 | + { |
|
386 | + $this->useStaticItemCaching = $useStaticItemCaching; |
|
387 | + return $this; |
|
388 | + } |
|
389 | 389 | } |
@@ -19,15 +19,15 @@ |
||
19 | 19 | |
20 | 20 | interface ConfigurationOptionInterface |
21 | 21 | { |
22 | - /** |
|
23 | - * @param $args |
|
24 | - * ArrayObject constructor. |
|
25 | - */ |
|
26 | - public function __construct(...$args); |
|
22 | + /** |
|
23 | + * @param $args |
|
24 | + * ArrayObject constructor. |
|
25 | + */ |
|
26 | + public function __construct(...$args); |
|
27 | 27 | |
28 | - /** |
|
29 | - * @param string $optionName |
|
30 | - * @return mixed|null |
|
31 | - */ |
|
32 | - public function isValidOption(string $optionName); |
|
28 | + /** |
|
29 | + * @param string $optionName |
|
30 | + * @return mixed|null |
|
31 | + */ |
|
32 | + public function isValidOption(string $optionName); |
|
33 | 33 | } |
@@ -22,35 +22,35 @@ |
||
22 | 22 | */ |
23 | 23 | trait EventManagerDispatcherTrait |
24 | 24 | { |
25 | - /** |
|
26 | - * @var EventManagerInterface |
|
27 | - */ |
|
28 | - protected $eventManager; |
|
25 | + /** |
|
26 | + * @var EventManagerInterface |
|
27 | + */ |
|
28 | + protected $eventManager; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @return EventManagerInterface |
|
32 | - */ |
|
33 | - public function getEventManager(): EventManagerInterface |
|
34 | - { |
|
35 | - return $this->eventManager; |
|
36 | - } |
|
30 | + /** |
|
31 | + * @return EventManagerInterface |
|
32 | + */ |
|
33 | + public function getEventManager(): EventManagerInterface |
|
34 | + { |
|
35 | + return $this->eventManager; |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * @param EventManagerInterface $em |
|
40 | - * @return EventManagerDispatcherInterface |
|
41 | - */ |
|
42 | - public function setEventManager(EventManagerInterface $em): EventManagerDispatcherInterface |
|
43 | - { |
|
44 | - $this->eventManager = $em; |
|
38 | + /** |
|
39 | + * @param EventManagerInterface $em |
|
40 | + * @return EventManagerDispatcherInterface |
|
41 | + */ |
|
42 | + public function setEventManager(EventManagerInterface $em): EventManagerDispatcherInterface |
|
43 | + { |
|
44 | + $this->eventManager = $em; |
|
45 | 45 | |
46 | - return $this; |
|
47 | - } |
|
46 | + return $this; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @return bool |
|
51 | - */ |
|
52 | - public function hasEventManager(): bool |
|
53 | - { |
|
54 | - return isset($this->eventManager); |
|
55 | - } |
|
49 | + /** |
|
50 | + * @return bool |
|
51 | + */ |
|
52 | + public function hasEventManager(): bool |
|
53 | + { |
|
54 | + return isset($this->eventManager); |
|
55 | + } |
|
56 | 56 | } |
57 | 57 | \ No newline at end of file |
@@ -25,35 +25,35 @@ |
||
25 | 25 | */ |
26 | 26 | interface EventManagerInterface |
27 | 27 | { |
28 | - /** |
|
29 | - * @return self |
|
30 | - */ |
|
31 | - public static function getInstance(): self; |
|
32 | - |
|
33 | - /** |
|
34 | - * @param string $eventName |
|
35 | - * @param array ...$args |
|
36 | - */ |
|
37 | - public function dispatch(string $eventName, ...$args): void; |
|
38 | - |
|
39 | - /** |
|
40 | - * @param string $name |
|
41 | - * @param array $arguments |
|
42 | - * @throws PhpfastcacheInvalidArgumentException |
|
43 | - * @throws BadMethodCallException |
|
44 | - */ |
|
45 | - public function __call(string $name, array $arguments): void; |
|
46 | - |
|
47 | - /** |
|
48 | - * @param callable $callback |
|
49 | - * @param string $callbackName |
|
50 | - */ |
|
51 | - public function onEveryEvents(callable $callback, string $callbackName): void; |
|
52 | - |
|
53 | - /** |
|
54 | - * @param string $eventName |
|
55 | - * @param string $callbackName |
|
56 | - * @return bool |
|
57 | - */ |
|
58 | - public function unbindEventCallback(string $eventName, string $callbackName): bool; |
|
28 | + /** |
|
29 | + * @return self |
|
30 | + */ |
|
31 | + public static function getInstance(): self; |
|
32 | + |
|
33 | + /** |
|
34 | + * @param string $eventName |
|
35 | + * @param array ...$args |
|
36 | + */ |
|
37 | + public function dispatch(string $eventName, ...$args): void; |
|
38 | + |
|
39 | + /** |
|
40 | + * @param string $name |
|
41 | + * @param array $arguments |
|
42 | + * @throws PhpfastcacheInvalidArgumentException |
|
43 | + * @throws BadMethodCallException |
|
44 | + */ |
|
45 | + public function __call(string $name, array $arguments): void; |
|
46 | + |
|
47 | + /** |
|
48 | + * @param callable $callback |
|
49 | + * @param string $callbackName |
|
50 | + */ |
|
51 | + public function onEveryEvents(callable $callback, string $callbackName): void; |
|
52 | + |
|
53 | + /** |
|
54 | + * @param string $eventName |
|
55 | + * @param string $callbackName |
|
56 | + * @return bool |
|
57 | + */ |
|
58 | + public function unbindEventCallback(string $eventName, string $callbackName): bool; |
|
59 | 59 | } |
60 | 60 | \ No newline at end of file |
@@ -22,19 +22,19 @@ |
||
22 | 22 | */ |
23 | 23 | interface EventManagerDispatcherInterface |
24 | 24 | { |
25 | - /** |
|
26 | - * @return EventManagerInterface |
|
27 | - */ |
|
28 | - public function getEventManager(): EventManagerInterface; |
|
25 | + /** |
|
26 | + * @return EventManagerInterface |
|
27 | + */ |
|
28 | + public function getEventManager(): EventManagerInterface; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @param EventManagerInterface $eventManager |
|
32 | - * @return mixed |
|
33 | - */ |
|
34 | - public function setEventManager(EventManagerInterface $eventManager): self; |
|
30 | + /** |
|
31 | + * @param EventManagerInterface $eventManager |
|
32 | + * @return mixed |
|
33 | + */ |
|
34 | + public function setEventManager(EventManagerInterface $eventManager): self; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @return bool |
|
38 | - */ |
|
39 | - public function hasEventManager(): bool; |
|
36 | + /** |
|
37 | + * @return bool |
|
38 | + */ |
|
39 | + public function hasEventManager(): bool; |
|
40 | 40 | } |
41 | 41 | \ No newline at end of file |
@@ -56,40 +56,40 @@ |
||
56 | 56 | */ |
57 | 57 | abstract class PhpfastcacheAbstractProxy |
58 | 58 | { |
59 | - /** |
|
60 | - * @var ExtendedCacheItemPoolInterface |
|
61 | - */ |
|
62 | - protected $instance; |
|
59 | + /** |
|
60 | + * @var ExtendedCacheItemPoolInterface |
|
61 | + */ |
|
62 | + protected $instance; |
|
63 | 63 | |
64 | - /** |
|
65 | - * PhpfastcacheAbstractProxy constructor. |
|
66 | - * @param string $driver |
|
67 | - * @param null $config |
|
68 | - * @throws \Phpfastcache\Exceptions\PhpfastcacheDriverCheckException |
|
69 | - * @throws \Phpfastcache\Exceptions\PhpfastcacheDriverException |
|
70 | - * @throws \Phpfastcache\Exceptions\PhpfastcacheDriverNotFoundException |
|
71 | - * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException |
|
72 | - * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidConfigurationException |
|
73 | - * @throws \Phpfastcache\Exceptions\PhpfastcacheLogicException |
|
74 | - * @throws \ReflectionException |
|
75 | - */ |
|
76 | - public function __construct(string $driver, $config = null) |
|
77 | - { |
|
78 | - $this->instance = CacheManager::getInstance($driver, $config); |
|
79 | - } |
|
64 | + /** |
|
65 | + * PhpfastcacheAbstractProxy constructor. |
|
66 | + * @param string $driver |
|
67 | + * @param null $config |
|
68 | + * @throws \Phpfastcache\Exceptions\PhpfastcacheDriverCheckException |
|
69 | + * @throws \Phpfastcache\Exceptions\PhpfastcacheDriverException |
|
70 | + * @throws \Phpfastcache\Exceptions\PhpfastcacheDriverNotFoundException |
|
71 | + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException |
|
72 | + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidConfigurationException |
|
73 | + * @throws \Phpfastcache\Exceptions\PhpfastcacheLogicException |
|
74 | + * @throws \ReflectionException |
|
75 | + */ |
|
76 | + public function __construct(string $driver, $config = null) |
|
77 | + { |
|
78 | + $this->instance = CacheManager::getInstance($driver, $config); |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * @param string $name |
|
83 | - * @param array $args |
|
84 | - * @return mixed |
|
85 | - * @throws BadMethodCallException |
|
86 | - */ |
|
87 | - public function __call(string $name, array $args) |
|
88 | - { |
|
89 | - if (\method_exists($this->instance, $name)) { |
|
90 | - return $this->instance->$name(...$args); |
|
91 | - } |
|
81 | + /** |
|
82 | + * @param string $name |
|
83 | + * @param array $args |
|
84 | + * @return mixed |
|
85 | + * @throws BadMethodCallException |
|
86 | + */ |
|
87 | + public function __call(string $name, array $args) |
|
88 | + { |
|
89 | + if (\method_exists($this->instance, $name)) { |
|
90 | + return $this->instance->$name(...$args); |
|
91 | + } |
|
92 | 92 | |
93 | - throw new BadMethodCallException(\sprintf('Method %s does not exists', $name)); |
|
94 | - } |
|
93 | + throw new BadMethodCallException(\sprintf('Method %s does not exists', $name)); |
|
94 | + } |
|
95 | 95 | } |
@@ -23,17 +23,17 @@ |
||
23 | 23 | */ |
24 | 24 | class PhpfastcacheIOException extends PhpfastcacheCoreException |
25 | 25 | { |
26 | - /** |
|
27 | - * @inheritdoc |
|
28 | - */ |
|
29 | - public function __construct($message = "", $code = 0, $previous = null) |
|
30 | - { |
|
31 | - $lastError = error_get_last(); |
|
32 | - if ($lastError) { |
|
33 | - $message .= "\n"; |
|
34 | - $message .= "Additional information provided by error_get_last():\n"; |
|
35 | - $message .= "{$lastError['message']} in {$lastError['file']} line {$lastError['line']}"; |
|
36 | - } |
|
37 | - parent::__construct($message, $code, $previous); |
|
38 | - } |
|
26 | + /** |
|
27 | + * @inheritdoc |
|
28 | + */ |
|
29 | + public function __construct($message = "", $code = 0, $previous = null) |
|
30 | + { |
|
31 | + $lastError = error_get_last(); |
|
32 | + if ($lastError) { |
|
33 | + $message .= "\n"; |
|
34 | + $message .= "Additional information provided by error_get_last():\n"; |
|
35 | + $message .= "{$lastError['message']} in {$lastError['file']} line {$lastError['line']}"; |
|
36 | + } |
|
37 | + parent::__construct($message, $code, $previous); |
|
38 | + } |
|
39 | 39 | } |
40 | 40 | \ No newline at end of file |
@@ -23,14 +23,14 @@ |
||
23 | 23 | */ |
24 | 24 | class PhpfastcacheInvalidArgumentTypeException extends PhpfastcacheInvalidArgumentException |
25 | 25 | { |
26 | - /** |
|
27 | - * @link https://php.net/manual/en/exception.construct.php |
|
28 | - * @param string $expectedType |
|
29 | - * @param mixed $unexpectedData |
|
30 | - */ |
|
31 | - public function __construct($expectedType, $unexpectedData) |
|
32 | - { |
|
33 | - $type = gettype($unexpectedData); |
|
34 | - parent::__construct("Expecting '{$expectedType}', got '" . ($type === 'object' ? $type . '(' . get_class($type) . ')' : $type) . "'"); |
|
35 | - } |
|
26 | + /** |
|
27 | + * @link https://php.net/manual/en/exception.construct.php |
|
28 | + * @param string $expectedType |
|
29 | + * @param mixed $unexpectedData |
|
30 | + */ |
|
31 | + public function __construct($expectedType, $unexpectedData) |
|
32 | + { |
|
33 | + $type = gettype($unexpectedData); |
|
34 | + parent::__construct("Expecting '{$expectedType}', got '" . ($type === 'object' ? $type . '(' . get_class($type) . ')' : $type) . "'"); |
|
35 | + } |
|
36 | 36 | } |
37 | 37 | \ No newline at end of file |