@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | * |
72 | 72 | * @var array |
73 | 73 | */ |
74 | - protected $config = []; |
|
74 | + protected $config = [ ]; |
|
75 | 75 | |
76 | 76 | /** |
77 | 77 | * @var ?CacheInterface |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | /** |
82 | 82 | * Constructeur |
83 | 83 | */ |
84 | - public function __construct(array $config = []) |
|
84 | + public function __construct(array $config = [ ]) |
|
85 | 85 | { |
86 | 86 | $this->setConfig($config); |
87 | 87 | } |
@@ -102,48 +102,48 @@ discard block |
||
102 | 102 | */ |
103 | 103 | protected function factory(): CacheInterface |
104 | 104 | { |
105 | - if (! static::$_enabled) { |
|
105 | + if (!static::$_enabled) { |
|
106 | 106 | return new Dummy(); |
107 | 107 | } |
108 | - if (! empty($this->adapter)) { |
|
108 | + if (!empty($this->adapter)) { |
|
109 | 109 | return $this->adapter; |
110 | 110 | } |
111 | 111 | |
112 | - $validHandlers = $this->config['valid_handlers'] ?? self::$validHandlers; |
|
112 | + $validHandlers = $this->config[ 'valid_handlers' ] ?? self::$validHandlers; |
|
113 | 113 | |
114 | - if (empty($validHandlers) || ! is_array($validHandlers)) { |
|
114 | + if (empty($validHandlers) || !is_array($validHandlers)) { |
|
115 | 115 | throw new InvalidArgumentException('Cache config must have an array of $valid_handlers.'); |
116 | 116 | } |
117 | 117 | |
118 | - $handler = $this->config['handler'] ?? null; |
|
119 | - $fallback = $this->config['fallback_handler'] ?? null; |
|
118 | + $handler = $this->config[ 'handler' ] ?? null; |
|
119 | + $fallback = $this->config[ 'fallback_handler' ] ?? null; |
|
120 | 120 | |
121 | 121 | if (empty($handler)) { |
122 | 122 | throw new InvalidArgumentException('Cache config must have a handler set.'); |
123 | 123 | } |
124 | 124 | |
125 | - if (! array_key_exists($handler, $validHandlers)) { |
|
125 | + if (!array_key_exists($handler, $validHandlers)) { |
|
126 | 126 | throw new InvalidArgumentException('Cache config has an invalid handler specified.'); |
127 | 127 | } |
128 | 128 | |
129 | - $adapter = new $validHandlers[$handler](); |
|
130 | - if (! ($adapter instanceof BaseHandler)) { |
|
129 | + $adapter = new $validHandlers[ $handler ](); |
|
130 | + if (!($adapter instanceof BaseHandler)) { |
|
131 | 131 | if (empty($fallback)) { |
132 | 132 | $adapter = new Dummy(); |
133 | - } elseif (! array_key_exists($fallback, $validHandlers)) { |
|
133 | + } elseif (!array_key_exists($fallback, $validHandlers)) { |
|
134 | 134 | throw new InvalidArgumentException('Cache config has an invalid fallback handler specified.'); |
135 | 135 | } else { |
136 | - $adapter = new $validHandlers[$fallback](); |
|
136 | + $adapter = new $validHandlers[ $fallback ](); |
|
137 | 137 | } |
138 | 138 | } |
139 | 139 | |
140 | - if (! ($adapter instanceof BaseHandler)) { |
|
140 | + if (!($adapter instanceof BaseHandler)) { |
|
141 | 141 | throw new InvalidArgumentException( |
142 | 142 | 'Cache handler must use BlitzPHP\Cache\Handlers\BaseHandler as a base class.' |
143 | 143 | ); |
144 | 144 | } |
145 | 145 | |
146 | - if (! $adapter->init($this->config)) { |
|
146 | + if (!$adapter->init($this->config)) { |
|
147 | 147 | throw new RuntimeException( |
148 | 148 | sprintf( |
149 | 149 | 'Cache engine %s is not properly configured. Check error log for additional information.', |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | /** |
30 | 30 | * {@inheritDoc} |
31 | 31 | */ |
32 | - public function init(array $config = []): bool |
|
32 | + public function init(array $config = [ ]): bool |
|
33 | 33 | { |
34 | 34 | return true; |
35 | 35 | } |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | */ |
64 | 64 | public function getMultiple($keys, $default = null): iterable |
65 | 65 | { |
66 | - return []; |
|
66 | + return [ ]; |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | */ |
65 | 65 | protected $_defaultConfig = [ |
66 | 66 | 'duration' => 3600, |
67 | - 'groups' => [], |
|
67 | + 'groups' => [ ], |
|
68 | 68 | 'prefix' => 'blitz_', |
69 | 69 | 'warnOnWriteFailures' => true, |
70 | 70 | ]; |
@@ -87,16 +87,16 @@ discard block |
||
87 | 87 | * |
88 | 88 | * @return bool Vrai si le moteur a été initialisé avec succès, faux sinon |
89 | 89 | */ |
90 | - public function init(array $config = []): bool |
|
90 | + public function init(array $config = [ ]): bool |
|
91 | 91 | { |
92 | 92 | $this->setConfig($config); |
93 | 93 | |
94 | - if (! empty($this->_config['groups'])) { |
|
95 | - sort($this->_config['groups']); |
|
96 | - $this->_groupPrefix = str_repeat('%s_', count($this->_config['groups'])); |
|
94 | + if (!empty($this->_config[ 'groups' ])) { |
|
95 | + sort($this->_config[ 'groups' ]); |
|
96 | + $this->_groupPrefix = str_repeat('%s_', count($this->_config[ 'groups' ])); |
|
97 | 97 | } |
98 | - if (! is_numeric($this->_config['duration'])) { |
|
99 | - $this->_config['duration'] = strtotime($this->_config['duration']) - time(); |
|
98 | + if (!is_numeric($this->_config[ 'duration' ])) { |
|
99 | + $this->_config[ 'duration' ] = strtotime($this->_config[ 'duration' ]) - time(); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | return true; |
@@ -117,13 +117,13 @@ discard block |
||
117 | 117 | */ |
118 | 118 | public function ensureValidKey(string $key): void |
119 | 119 | { |
120 | - if (! is_string($key) || $key === '') { |
|
120 | + if (!is_string($key) || $key === '') { |
|
121 | 121 | throw new InvalidArgumentException('A cache key must be a non-empty string.'); |
122 | 122 | } |
123 | 123 | |
124 | 124 | $reserved = self::$reservedCharacters; |
125 | 125 | if ($reserved && strpbrk($key, $reserved) !== false) { |
126 | - throw new InvalidArgumentException('Cache key contains reserved characters ' . $reserved); |
|
126 | + throw new InvalidArgumentException('Cache key contains reserved characters '.$reserved); |
|
127 | 127 | } |
128 | 128 | } |
129 | 129 | |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | */ |
138 | 138 | protected function ensureValidType($iterable, string $check = self::CHECK_VALUE): void |
139 | 139 | { |
140 | - if (! is_iterable($iterable)) { |
|
140 | + if (!is_iterable($iterable)) { |
|
141 | 141 | throw new InvalidArgumentException(sprintf( |
142 | 142 | 'A cache %s must be either an array or a Traversable.', |
143 | 143 | $check === self::CHECK_VALUE ? 'key set' : 'set' |
@@ -198,10 +198,10 @@ discard block |
||
198 | 198 | { |
199 | 199 | $this->ensureValidType($keys); |
200 | 200 | |
201 | - $results = []; |
|
201 | + $results = [ ]; |
|
202 | 202 | |
203 | 203 | foreach ($keys as $key) { |
204 | - $results[$key] = $this->get($key, $default); |
|
204 | + $results[ $key ] = $this->get($key, $default); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | return $results; |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | $result = true; |
267 | 267 | |
268 | 268 | foreach ($keys as $key) { |
269 | - if (! $this->delete($key)) { |
|
269 | + if (!$this->delete($key)) { |
|
270 | 270 | $result = false; |
271 | 271 | } |
272 | 272 | } |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | */ |
360 | 360 | public function groups(): array |
361 | 361 | { |
362 | - return $this->_config['groups']; |
|
362 | + return $this->_config[ 'groups' ]; |
|
363 | 363 | } |
364 | 364 | |
365 | 365 | /** |
@@ -384,7 +384,7 @@ discard block |
||
384 | 384 | } |
385 | 385 | $key = preg_replace('/[\s]+/', '_', $key); |
386 | 386 | |
387 | - return $this->_config['prefix'] . $prefix . $key; |
|
387 | + return $this->_config[ 'prefix' ].$prefix.$key; |
|
388 | 388 | } |
389 | 389 | |
390 | 390 | /** |
@@ -409,7 +409,7 @@ discard block |
||
409 | 409 | protected function duration($ttl): int |
410 | 410 | { |
411 | 411 | if ($ttl === null) { |
412 | - return $this->_config['duration']; |
|
412 | + return $this->_config[ 'duration' ]; |
|
413 | 413 | } |
414 | 414 | if (is_int($ttl)) { |
415 | 415 | return $ttl; |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | */ |
48 | 48 | protected $_defaultConfig = [ |
49 | 49 | 'duration' => 3600, |
50 | - 'groups' => [], |
|
50 | + 'groups' => [ ], |
|
51 | 51 | 'lock' => true, |
52 | 52 | 'mask' => 0664, |
53 | 53 | 'path' => null, |
@@ -65,15 +65,15 @@ discard block |
||
65 | 65 | /** |
66 | 66 | * {@inheritDoc} |
67 | 67 | */ |
68 | - public function init(array $config = []): bool |
|
68 | + public function init(array $config = [ ]): bool |
|
69 | 69 | { |
70 | 70 | parent::init($config); |
71 | 71 | |
72 | - if ($this->_config['path'] === null) { |
|
73 | - $this->_config['path'] = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'blitz-php' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR; |
|
72 | + if ($this->_config[ 'path' ] === null) { |
|
73 | + $this->_config[ 'path' ] = sys_get_temp_dir().DIRECTORY_SEPARATOR.'blitz-php'.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR; |
|
74 | 74 | } |
75 | - if (substr($this->_config['path'], -1) !== DIRECTORY_SEPARATOR) { |
|
76 | - $this->_config['path'] .= DIRECTORY_SEPARATOR; |
|
75 | + if (substr($this->_config[ 'path' ], -1) !== DIRECTORY_SEPARATOR) { |
|
76 | + $this->_config[ 'path' ] .= DIRECTORY_SEPARATOR; |
|
77 | 77 | } |
78 | 78 | if ($this->_groupPrefix) { |
79 | 79 | $this->_groupPrefix = str_replace('_', DIRECTORY_SEPARATOR, $this->_groupPrefix); |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | */ |
88 | 88 | public function set($key, $value, $ttl = null): bool |
89 | 89 | { |
90 | - if ($value === '' || ! $this->_init) { |
|
90 | + if ($value === '' || !$this->_init) { |
|
91 | 91 | return false; |
92 | 92 | } |
93 | 93 | |
@@ -97,14 +97,14 @@ discard block |
||
97 | 97 | return false; |
98 | 98 | } |
99 | 99 | |
100 | - if (! empty($this->_config['serialize'])) { |
|
100 | + if (!empty($this->_config[ 'serialize' ])) { |
|
101 | 101 | $value = serialize($value); |
102 | 102 | } |
103 | 103 | |
104 | 104 | $expires = time() + $this->duration($ttl); |
105 | - $contents = implode('', [$expires, PHP_EOL, $value, PHP_EOL]); |
|
105 | + $contents = implode('', [ $expires, PHP_EOL, $value, PHP_EOL ]); |
|
106 | 106 | |
107 | - if ($this->_config['lock']) { |
|
107 | + if ($this->_config[ 'lock' ]) { |
|
108 | 108 | /** @psalm-suppress PossiblyNullReference */ |
109 | 109 | $this->_File->flock(LOCK_EX); |
110 | 110 | } |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | && $this->_File->fwrite($contents) |
116 | 116 | && $this->_File->fflush(); |
117 | 117 | |
118 | - if ($this->_config['lock']) { |
|
118 | + if ($this->_config[ 'lock' ]) { |
|
119 | 119 | $this->_File->flock(LOCK_UN); |
120 | 120 | } |
121 | 121 | $this->_File = null; |
@@ -130,11 +130,11 @@ discard block |
||
130 | 130 | { |
131 | 131 | $key = $this->_key($key); |
132 | 132 | |
133 | - if (! $this->_init || $this->_setKey($key) === false) { |
|
133 | + if (!$this->_init || $this->_setKey($key) === false) { |
|
134 | 134 | return $default; |
135 | 135 | } |
136 | 136 | |
137 | - if ($this->_config['lock']) { |
|
137 | + if ($this->_config[ 'lock' ]) { |
|
138 | 138 | /** @psalm-suppress PossiblyNullReference */ |
139 | 139 | $this->_File->flock(LOCK_SH); |
140 | 140 | } |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | $cachetime = (int) $this->_File->current(); |
146 | 146 | |
147 | 147 | if ($cachetime < $time) { |
148 | - if ($this->_config['lock']) { |
|
148 | + if ($this->_config[ 'lock' ]) { |
|
149 | 149 | $this->_File->flock(LOCK_UN); |
150 | 150 | } |
151 | 151 | |
@@ -161,13 +161,13 @@ discard block |
||
161 | 161 | $this->_File->next(); |
162 | 162 | } |
163 | 163 | |
164 | - if ($this->_config['lock']) { |
|
164 | + if ($this->_config[ 'lock' ]) { |
|
165 | 165 | $this->_File->flock(LOCK_UN); |
166 | 166 | } |
167 | 167 | |
168 | 168 | $data = trim($data); |
169 | 169 | |
170 | - if ($data !== '' && ! empty($this->_config['serialize'])) { |
|
170 | + if ($data !== '' && !empty($this->_config[ 'serialize' ])) { |
|
171 | 171 | $data = unserialize($data); |
172 | 172 | } |
173 | 173 | |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | { |
182 | 182 | $key = $this->_key($key); |
183 | 183 | |
184 | - if ($this->_setKey($key) === false || ! $this->_init) { |
|
184 | + if ($this->_setKey($key) === false || !$this->_init) { |
|
185 | 185 | return false; |
186 | 186 | } |
187 | 187 | |
@@ -203,22 +203,22 @@ discard block |
||
203 | 203 | */ |
204 | 204 | public function clear(): bool |
205 | 205 | { |
206 | - if (! $this->_init) { |
|
206 | + if (!$this->_init) { |
|
207 | 207 | return false; |
208 | 208 | } |
209 | 209 | $this->_File = null; |
210 | 210 | |
211 | - $this->_clearDirectory($this->_config['path']); |
|
211 | + $this->_clearDirectory($this->_config[ 'path' ]); |
|
212 | 212 | |
213 | 213 | $directory = new RecursiveDirectoryIterator( |
214 | - $this->_config['path'], |
|
214 | + $this->_config[ 'path' ], |
|
215 | 215 | FilesystemIterator::SKIP_DOTS |
216 | 216 | ); |
217 | 217 | $contents = new RecursiveIteratorIterator( |
218 | 218 | $directory, |
219 | 219 | RecursiveIteratorIterator::SELF_FIRST |
220 | 220 | ); |
221 | - $cleared = []; |
|
221 | + $cleared = [ ]; |
|
222 | 222 | /** @var SplFileInfo $fileInfo */ |
223 | 223 | foreach ($contents as $fileInfo) { |
224 | 224 | if ($fileInfo->isFile()) { |
@@ -228,16 +228,16 @@ discard block |
||
228 | 228 | } |
229 | 229 | |
230 | 230 | $realPath = $fileInfo->getRealPath(); |
231 | - if (! $realPath) { |
|
231 | + if (!$realPath) { |
|
232 | 232 | unset($fileInfo); |
233 | 233 | |
234 | 234 | continue; |
235 | 235 | } |
236 | 236 | |
237 | - $path = $realPath . DIRECTORY_SEPARATOR; |
|
238 | - if (! in_array($path, $cleared, true)) { |
|
237 | + $path = $realPath.DIRECTORY_SEPARATOR; |
|
238 | + if (!in_array($path, $cleared, true)) { |
|
239 | 239 | $this->_clearDirectory($path); |
240 | - $cleared[] = $path; |
|
240 | + $cleared[ ] = $path; |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | // les itérateurs internes possibles doivent également être désactivés pour que les verrous sur les parents soient libérés |
@@ -256,24 +256,24 @@ discard block |
||
256 | 256 | */ |
257 | 257 | protected function _clearDirectory(string $path): void |
258 | 258 | { |
259 | - if (! is_dir($path)) { |
|
259 | + if (!is_dir($path)) { |
|
260 | 260 | return; |
261 | 261 | } |
262 | 262 | |
263 | 263 | $dir = dir($path); |
264 | - if (! $dir) { |
|
264 | + if (!$dir) { |
|
265 | 265 | return; |
266 | 266 | } |
267 | 267 | |
268 | - $prefixLength = strlen($this->_config['prefix']); |
|
268 | + $prefixLength = strlen($this->_config[ 'prefix' ]); |
|
269 | 269 | |
270 | 270 | while (($entry = $dir->read()) !== false) { |
271 | - if (substr($entry, 0, $prefixLength) !== $this->_config['prefix']) { |
|
271 | + if (substr($entry, 0, $prefixLength) !== $this->_config[ 'prefix' ]) { |
|
272 | 272 | continue; |
273 | 273 | } |
274 | 274 | |
275 | 275 | try { |
276 | - $file = new SplFileObject($path . $entry, 'r'); |
|
276 | + $file = new SplFileObject($path.$entry, 'r'); |
|
277 | 277 | } catch (Exception $e) { |
278 | 278 | continue; |
279 | 279 | } |
@@ -325,15 +325,15 @@ discard block |
||
325 | 325 | if ($this->_groupPrefix) { |
326 | 326 | $groups = vsprintf($this->_groupPrefix, $this->groups()); |
327 | 327 | } |
328 | - $dir = $this->_config['path'] . $groups; |
|
328 | + $dir = $this->_config[ 'path' ].$groups; |
|
329 | 329 | |
330 | - if (! is_dir($dir)) { |
|
330 | + if (!is_dir($dir)) { |
|
331 | 331 | mkdir($dir, 0775, true); |
332 | 332 | } |
333 | 333 | |
334 | - $path = new SplFileInfo($dir . $key); |
|
334 | + $path = new SplFileInfo($dir.$key); |
|
335 | 335 | |
336 | - if (! $createKey && ! $path->isFile()) { |
|
336 | + if (!$createKey && !$path->isFile()) { |
|
337 | 337 | return false; |
338 | 338 | } |
339 | 339 | if ( |
@@ -352,11 +352,11 @@ discard block |
||
352 | 352 | } |
353 | 353 | unset($path); |
354 | 354 | |
355 | - if (! $exists && ! chmod($this->_File->getPathname(), (int) $this->_config['mask'])) { |
|
355 | + if (!$exists && !chmod($this->_File->getPathname(), (int) $this->_config[ 'mask' ])) { |
|
356 | 356 | trigger_error(sprintf( |
357 | 357 | 'Could not apply permission mask "%s" on cache file "%s"', |
358 | 358 | $this->_File->getPathname(), |
359 | - $this->_config['mask'] |
|
359 | + $this->_config[ 'mask' ] |
|
360 | 360 | ), E_USER_WARNING); |
361 | 361 | } |
362 | 362 | } |
@@ -369,21 +369,21 @@ discard block |
||
369 | 369 | */ |
370 | 370 | protected function _active(): bool |
371 | 371 | { |
372 | - $dir = new SplFileInfo($this->_config['path']); |
|
372 | + $dir = new SplFileInfo($this->_config[ 'path' ]); |
|
373 | 373 | $path = $dir->getPathname(); |
374 | 374 | $success = true; |
375 | - if (! is_dir($path)) { |
|
375 | + if (!is_dir($path)) { |
|
376 | 376 | // phpcs:disable |
377 | 377 | $success = @mkdir($path, 0775, true); |
378 | 378 | // phpcs:enable |
379 | 379 | } |
380 | 380 | |
381 | 381 | $isWritableDir = ($dir->isDir() && $dir->isWritable()); |
382 | - if (! $success || ($this->_init && ! $isWritableDir)) { |
|
382 | + if (!$success || ($this->_init && !$isWritableDir)) { |
|
383 | 383 | $this->_init = false; |
384 | 384 | trigger_error(sprintf( |
385 | 385 | '%s is not writable', |
386 | - $this->_config['path'] |
|
386 | + $this->_config[ 'path' ] |
|
387 | 387 | ), E_USER_WARNING); |
388 | 388 | } |
389 | 389 | |
@@ -399,7 +399,7 @@ discard block |
||
399 | 399 | |
400 | 400 | if (preg_match('/[\/\\<>?:|*"]/', $key)) { |
401 | 401 | throw new InvalidArgumentException( |
402 | - "Cache key `{$key}` contains invalid characters. " . |
|
402 | + "Cache key `{$key}` contains invalid characters. ". |
|
403 | 403 | 'You cannot use /, \\, <, >, ?, :, |, *, or " in cache keys.' |
404 | 404 | ); |
405 | 405 | } |
@@ -414,17 +414,17 @@ discard block |
||
414 | 414 | { |
415 | 415 | $this->_File = null; |
416 | 416 | |
417 | - $prefix = (string) $this->_config['prefix']; |
|
417 | + $prefix = (string) $this->_config[ 'prefix' ]; |
|
418 | 418 | |
419 | - $directoryIterator = new RecursiveDirectoryIterator($this->_config['path']); |
|
419 | + $directoryIterator = new RecursiveDirectoryIterator($this->_config[ 'path' ]); |
|
420 | 420 | $contents = new RecursiveIteratorIterator( |
421 | 421 | $directoryIterator, |
422 | 422 | RecursiveIteratorIterator::CHILD_FIRST |
423 | 423 | ); |
424 | 424 | $filtered = new CallbackFilterIterator( |
425 | 425 | $contents, |
426 | - static function (SplFileInfo $current) use ($group, $prefix) { |
|
427 | - if (! $current->isFile()) { |
|
426 | + static function(SplFileInfo $current) use ($group, $prefix) { |
|
427 | + if (!$current->isFile()) { |
|
428 | 428 | return false; |
429 | 429 | } |
430 | 430 | |
@@ -436,7 +436,7 @@ discard block |
||
436 | 436 | |
437 | 437 | $pos = strpos( |
438 | 438 | $current->getPathname(), |
439 | - DIRECTORY_SEPARATOR . $group . DIRECTORY_SEPARATOR |
|
439 | + DIRECTORY_SEPARATOR.$group.DIRECTORY_SEPARATOR |
|
440 | 440 | ); |
441 | 441 | |
442 | 442 | return $pos !== false; |