@@ -26,14 +26,14 @@ discard block |
||
| 26 | 26 | * |
| 27 | 27 | * @var list<string> |
| 28 | 28 | */ |
| 29 | - protected array $_compiledGroupNames = []; |
|
| 29 | + protected array $_compiledGroupNames = [ ]; |
|
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | 32 | * {@inheritDoc} |
| 33 | 33 | */ |
| 34 | - public function init(array $config = []): bool |
|
| 34 | + public function init(array $config = [ ]): bool |
|
| 35 | 35 | { |
| 36 | - if (! extension_loaded('apcu')) { |
|
| 36 | + if (!extension_loaded('apcu')) { |
|
| 37 | 37 | throw new RuntimeException('L\'extension `apcu` doit être activée pour utiliser ApcuHandler.'); |
| 38 | 38 | } |
| 39 | 39 | |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | /** |
| 44 | 44 | * {@inheritDoc} |
| 45 | 45 | */ |
| 46 | - public function set(string $key, mixed $value, DateInterval|int|null $ttl = null): bool |
|
| 46 | + public function set(string $key, mixed $value, DateInterval | int | null $ttl = null): bool |
|
| 47 | 47 | { |
| 48 | 48 | $key = $this->_key($key); |
| 49 | 49 | $duration = $this->duration($ttl); |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | { |
| 113 | 113 | if (class_exists(APCUIterator::class, false)) { |
| 114 | 114 | $iterator = new APCUIterator( |
| 115 | - '/^' . preg_quote($this->_config['prefix'], '/') . '/', |
|
| 115 | + '/^'.preg_quote($this->_config[ 'prefix' ], '/').'/', |
|
| 116 | 116 | APC_ITER_NONE |
| 117 | 117 | ); |
| 118 | 118 | apcu_delete($iterator); |
@@ -122,9 +122,9 @@ discard block |
||
| 122 | 122 | |
| 123 | 123 | $cache = apcu_cache_info(); // Déclenche déjà un avertissement par lui-même |
| 124 | 124 | |
| 125 | - foreach ($cache['cache_list'] as $key) { |
|
| 126 | - if (str_starts_with($key['info'], $this->_config['prefix'])) { |
|
| 127 | - apcu_delete($key['info']); |
|
| 125 | + foreach ($cache[ 'cache_list' ] as $key) { |
|
| 126 | + if (str_starts_with($key[ 'info' ], $this->_config[ 'prefix' ])) { |
|
| 127 | + apcu_delete($key[ 'info' ]); |
|
| 128 | 128 | } |
| 129 | 129 | } |
| 130 | 130 | |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | public function add(string $key, mixed $value): bool |
| 140 | 140 | { |
| 141 | 141 | $key = $this->_key($key); |
| 142 | - $duration = $this->_config['duration']; |
|
| 142 | + $duration = $this->_config[ 'duration' ]; |
|
| 143 | 143 | |
| 144 | 144 | return apcu_add($key, $value, $duration); |
| 145 | 145 | } |
@@ -152,34 +152,34 @@ discard block |
||
| 152 | 152 | */ |
| 153 | 153 | public function groups(): array |
| 154 | 154 | { |
| 155 | - if ($this->_compiledGroupNames === []) { |
|
| 156 | - foreach ($this->_config['groups'] as $group) { |
|
| 157 | - $this->_compiledGroupNames[] = $this->_config['prefix'] . $group; |
|
| 155 | + if ($this->_compiledGroupNames === [ ]) { |
|
| 156 | + foreach ($this->_config[ 'groups' ] as $group) { |
|
| 157 | + $this->_compiledGroupNames[ ] = $this->_config[ 'prefix' ].$group; |
|
| 158 | 158 | } |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | $success = false; |
| 162 | 162 | $groups = apcu_fetch($this->_compiledGroupNames, $success); |
| 163 | - if ($success && count($groups) !== count($this->_config['groups'])) { |
|
| 163 | + if ($success && count($groups) !== count($this->_config[ 'groups' ])) { |
|
| 164 | 164 | foreach ($this->_compiledGroupNames as $group) { |
| 165 | - if (! isset($groups[$group])) { |
|
| 165 | + if (!isset($groups[ $group ])) { |
|
| 166 | 166 | $value = 1; |
| 167 | 167 | if (apcu_store($group, $value) === false) { |
| 168 | 168 | $this->warning( |
| 169 | 169 | sprintf('Impossible de stocker la clé "%s" avec la valeur "%s" dans le cache APCu.', $group, $value) |
| 170 | 170 | ); |
| 171 | 171 | } |
| 172 | - $groups[$group] = $value; |
|
| 172 | + $groups[ $group ] = $value; |
|
| 173 | 173 | } |
| 174 | 174 | } |
| 175 | 175 | ksort($groups); |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | - $result = []; |
|
| 178 | + $result = [ ]; |
|
| 179 | 179 | $groups = array_values($groups); |
| 180 | 180 | |
| 181 | - foreach ($this->_config['groups'] as $i => $group) { |
|
| 182 | - $result[] = $group . $groups[$i]; |
|
| 181 | + foreach ($this->_config[ 'groups' ] as $i => $group) { |
|
| 182 | + $result[ ] = $group.$groups[ $i ]; |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | return $result; |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | public function clearGroup(string $group): bool |
| 194 | 194 | { |
| 195 | 195 | $success = false; |
| 196 | - apcu_inc($this->_config['prefix'] . $group, 1, $success); |
|
| 196 | + apcu_inc($this->_config[ 'prefix' ].$group, 1, $success); |
|
| 197 | 197 | |
| 198 | 198 | return $success; |
| 199 | 199 | } |
@@ -47,14 +47,14 @@ discard block |
||
| 47 | 47 | * @var array<string, mixed> |
| 48 | 48 | */ |
| 49 | 49 | protected array $_defaultConfig = [ |
| 50 | - 'duration' => 3600, |
|
| 51 | - 'groups' => [], |
|
| 52 | - 'lock' => true, |
|
| 53 | - 'mask' => 0o664, |
|
| 54 | - 'dirMask' => 0770, |
|
| 55 | - 'path' => null, |
|
| 56 | - 'prefix' => 'blitz_', |
|
| 57 | - 'serialize' => true, |
|
| 50 | + 'duration' => 3600, |
|
| 51 | + 'groups' => [], |
|
| 52 | + 'lock' => true, |
|
| 53 | + 'mask' => 0o664, |
|
| 54 | + 'dirMask' => 0770, |
|
| 55 | + 'path' => null, |
|
| 56 | + 'prefix' => 'blitz_', |
|
| 57 | + 'serialize' => true, |
|
| 58 | 58 | ]; |
| 59 | 59 | |
| 60 | 60 | /** |
@@ -438,7 +438,7 @@ discard block |
||
| 438 | 438 | ); |
| 439 | 439 | |
| 440 | 440 | foreach ($filtered as $object) { |
| 441 | - /** @var \SplFileInfo $object */ |
|
| 441 | + /** @var \SplFileInfo $object */ |
|
| 442 | 442 | $path = $object->getPathname(); |
| 443 | 443 | unset($object); |
| 444 | 444 | // phpcs:ignore |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | protected array $_defaultConfig = [ |
| 50 | 50 | 'duration' => 3600, |
| 51 | - 'groups' => [], |
|
| 51 | + 'groups' => [ ], |
|
| 52 | 52 | 'lock' => true, |
| 53 | 53 | 'mask' => 0o664, |
| 54 | 54 | 'dirMask' => 0770, |
@@ -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); |
@@ -85,9 +85,9 @@ discard block |
||
| 85 | 85 | /** |
| 86 | 86 | * {@inheritDoc} |
| 87 | 87 | */ |
| 88 | - public function set(string $key, mixed $value, DateInterval|int|null $ttl = null): bool |
|
| 88 | + public function set(string $key, mixed $value, DateInterval | int | null $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 | $this->_File->flock(LOCK_EX); |
| 109 | 109 | } |
| 110 | 110 | |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | && $this->_File->fwrite($contents) |
| 114 | 114 | && $this->_File->fflush(); |
| 115 | 115 | |
| 116 | - if ($this->_config['lock']) { |
|
| 116 | + if ($this->_config[ 'lock' ]) { |
|
| 117 | 117 | $this->_File->flock(LOCK_UN); |
| 118 | 118 | } |
| 119 | 119 | unset($this->_File); |
@@ -128,11 +128,11 @@ discard block |
||
| 128 | 128 | { |
| 129 | 129 | $key = $this->_key($key); |
| 130 | 130 | |
| 131 | - if (! $this->_init || $this->_setKey($key) === false) { |
|
| 131 | + if (!$this->_init || $this->_setKey($key) === false) { |
|
| 132 | 132 | return $default; |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | - if ($this->_config['lock']) { |
|
| 135 | + if ($this->_config[ 'lock' ]) { |
|
| 136 | 136 | $this->_File->flock(LOCK_SH); |
| 137 | 137 | } |
| 138 | 138 | |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | $cachetime = (int) $this->_File->current(); |
| 142 | 142 | |
| 143 | 143 | if ($cachetime < $time) { |
| 144 | - if ($this->_config['lock']) { |
|
| 144 | + if ($this->_config[ 'lock' ]) { |
|
| 145 | 145 | $this->_File->flock(LOCK_UN); |
| 146 | 146 | } |
| 147 | 147 | |
@@ -156,13 +156,13 @@ discard block |
||
| 156 | 156 | $this->_File->next(); |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - if ($this->_config['lock']) { |
|
| 159 | + if ($this->_config[ 'lock' ]) { |
|
| 160 | 160 | $this->_File->flock(LOCK_UN); |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | $data = trim($data); |
| 164 | 164 | |
| 165 | - if ($data !== '' && ! empty($this->_config['serialize'])) { |
|
| 165 | + if ($data !== '' && !empty($this->_config[ 'serialize' ])) { |
|
| 166 | 166 | $data = unserialize($data); |
| 167 | 167 | } |
| 168 | 168 | |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | { |
| 177 | 177 | $key = $this->_key($key); |
| 178 | 178 | |
| 179 | - if ($this->_setKey($key) === false || ! $this->_init) { |
|
| 179 | + if ($this->_setKey($key) === false || !$this->_init) { |
|
| 180 | 180 | return false; |
| 181 | 181 | } |
| 182 | 182 | |
@@ -197,22 +197,22 @@ discard block |
||
| 197 | 197 | */ |
| 198 | 198 | public function clear(): bool |
| 199 | 199 | { |
| 200 | - if (! $this->_init) { |
|
| 200 | + if (!$this->_init) { |
|
| 201 | 201 | return false; |
| 202 | 202 | } |
| 203 | 203 | unset($this->_File); |
| 204 | 204 | |
| 205 | - $this->_clearDirectory($this->_config['path']); |
|
| 205 | + $this->_clearDirectory($this->_config[ 'path' ]); |
|
| 206 | 206 | |
| 207 | 207 | $directory = new RecursiveDirectoryIterator( |
| 208 | - $this->_config['path'], |
|
| 208 | + $this->_config[ 'path' ], |
|
| 209 | 209 | FilesystemIterator::SKIP_DOTS |
| 210 | 210 | ); |
| 211 | 211 | $contents = new RecursiveIteratorIterator( |
| 212 | 212 | $directory, |
| 213 | 213 | RecursiveIteratorIterator::SELF_FIRST |
| 214 | 214 | ); |
| 215 | - $cleared = []; |
|
| 215 | + $cleared = [ ]; |
|
| 216 | 216 | |
| 217 | 217 | /** @var SplFileInfo $fileInfo */ |
| 218 | 218 | foreach ($contents as $fileInfo) { |
@@ -223,16 +223,16 @@ discard block |
||
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | $realPath = $fileInfo->getRealPath(); |
| 226 | - if (! $realPath) { |
|
| 226 | + if (!$realPath) { |
|
| 227 | 227 | unset($fileInfo); |
| 228 | 228 | |
| 229 | 229 | continue; |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | - $path = $realPath . DIRECTORY_SEPARATOR; |
|
| 233 | - if (! in_array($path, $cleared, true)) { |
|
| 232 | + $path = $realPath.DIRECTORY_SEPARATOR; |
|
| 233 | + if (!in_array($path, $cleared, true)) { |
|
| 234 | 234 | $this->_clearDirectory($path); |
| 235 | - $cleared[] = $path; |
|
| 235 | + $cleared[ ] = $path; |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | // les itérateurs internes possibles doivent également être désactivés pour que les verrous sur les parents soient libérés |
@@ -251,24 +251,24 @@ discard block |
||
| 251 | 251 | */ |
| 252 | 252 | protected function _clearDirectory(string $path): void |
| 253 | 253 | { |
| 254 | - if (! is_dir($path)) { |
|
| 254 | + if (!is_dir($path)) { |
|
| 255 | 255 | return; |
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | $dir = dir($path); |
| 259 | - if (! $dir) { |
|
| 259 | + if (!$dir) { |
|
| 260 | 260 | return; |
| 261 | 261 | } |
| 262 | 262 | |
| 263 | - $prefixLength = strlen($this->_config['prefix']); |
|
| 263 | + $prefixLength = strlen($this->_config[ 'prefix' ]); |
|
| 264 | 264 | |
| 265 | 265 | while (($entry = $dir->read()) !== false) { |
| 266 | - if (substr($entry, 0, $prefixLength) !== $this->_config['prefix']) { |
|
| 266 | + if (substr($entry, 0, $prefixLength) !== $this->_config[ 'prefix' ]) { |
|
| 267 | 267 | continue; |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | try { |
| 271 | - $file = new SplFileObject($path . $entry, 'r'); |
|
| 271 | + $file = new SplFileObject($path.$entry, 'r'); |
|
| 272 | 272 | } catch (Exception $e) { |
| 273 | 273 | continue; |
| 274 | 274 | } |
@@ -311,7 +311,7 @@ discard block |
||
| 311 | 311 | */ |
| 312 | 312 | public function info() |
| 313 | 313 | { |
| 314 | - return $this->getDirFileInfo($this->_config['path']); |
|
| 314 | + return $this->getDirFileInfo($this->_config[ 'path' ]); |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | /** |
@@ -328,15 +328,15 @@ discard block |
||
| 328 | 328 | if ($this->_groupPrefix) { |
| 329 | 329 | $groups = vsprintf($this->_groupPrefix, $this->groups()); |
| 330 | 330 | } |
| 331 | - $dir = $this->_config['path'] . $groups; |
|
| 331 | + $dir = $this->_config[ 'path' ].$groups; |
|
| 332 | 332 | |
| 333 | - if (! is_dir($dir)) { |
|
| 334 | - mkdir($dir, $this->_config['dirMask'], true); |
|
| 333 | + if (!is_dir($dir)) { |
|
| 334 | + mkdir($dir, $this->_config[ 'dirMask' ], true); |
|
| 335 | 335 | } |
| 336 | 336 | |
| 337 | - $path = new SplFileInfo($dir . $key); |
|
| 337 | + $path = new SplFileInfo($dir.$key); |
|
| 338 | 338 | |
| 339 | - if (! $createKey && ! $path->isFile()) { |
|
| 339 | + if (!$createKey && !$path->isFile()) { |
|
| 340 | 340 | return false; |
| 341 | 341 | } |
| 342 | 342 | if ( |
@@ -355,11 +355,11 @@ discard block |
||
| 355 | 355 | } |
| 356 | 356 | unset($path); |
| 357 | 357 | |
| 358 | - if (! $exists && ! chmod($this->_File->getPathname(), (int) $this->_config['mask'])) { |
|
| 358 | + if (!$exists && !chmod($this->_File->getPathname(), (int) $this->_config[ 'mask' ])) { |
|
| 359 | 359 | trigger_error(sprintf( |
| 360 | 360 | 'Impossible d\'appliquer le masque d\'autorisation "%s" sur le fichier cache "%s"', |
| 361 | 361 | $this->_File->getPathname(), |
| 362 | - $this->_config['mask'] |
|
| 362 | + $this->_config[ 'mask' ] |
|
| 363 | 363 | ), E_USER_WARNING); |
| 364 | 364 | } |
| 365 | 365 | } |
@@ -372,21 +372,21 @@ discard block |
||
| 372 | 372 | */ |
| 373 | 373 | protected function _active(): bool |
| 374 | 374 | { |
| 375 | - $dir = new SplFileInfo($this->_config['path']); |
|
| 375 | + $dir = new SplFileInfo($this->_config[ 'path' ]); |
|
| 376 | 376 | $path = $dir->getPathname(); |
| 377 | 377 | $success = true; |
| 378 | - if (! is_dir($path)) { |
|
| 378 | + if (!is_dir($path)) { |
|
| 379 | 379 | // phpcs:disable |
| 380 | - $success = @mkdir($path, $this->_config['dirMask'], true); |
|
| 380 | + $success = @mkdir($path, $this->_config[ 'dirMask' ], true); |
|
| 381 | 381 | // phpcs:enable |
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | $isWritableDir = ($dir->isDir() && $dir->isWritable()); |
| 385 | - if (! $success || ($this->_init && ! $isWritableDir)) { |
|
| 385 | + if (!$success || ($this->_init && !$isWritableDir)) { |
|
| 386 | 386 | $this->_init = false; |
| 387 | 387 | trigger_error(sprintf( |
| 388 | 388 | '%s n\'est pas ecrivable', |
| 389 | - $this->_config['path'] |
|
| 389 | + $this->_config[ 'path' ] |
|
| 390 | 390 | ), E_USER_WARNING); |
| 391 | 391 | } |
| 392 | 392 | |
@@ -410,17 +410,17 @@ discard block |
||
| 410 | 410 | { |
| 411 | 411 | unset($this->_File); |
| 412 | 412 | |
| 413 | - $prefix = (string) $this->_config['prefix']; |
|
| 413 | + $prefix = (string) $this->_config[ 'prefix' ]; |
|
| 414 | 414 | |
| 415 | - $directoryIterator = new RecursiveDirectoryIterator($this->_config['path']); |
|
| 415 | + $directoryIterator = new RecursiveDirectoryIterator($this->_config[ 'path' ]); |
|
| 416 | 416 | $contents = new RecursiveIteratorIterator( |
| 417 | 417 | $directoryIterator, |
| 418 | 418 | RecursiveIteratorIterator::CHILD_FIRST |
| 419 | 419 | ); |
| 420 | 420 | $filtered = new CallbackFilterIterator( |
| 421 | 421 | $contents, |
| 422 | - static function (SplFileInfo $current) use ($group, $prefix) { |
|
| 423 | - if (! $current->isFile()) { |
|
| 422 | + static function(SplFileInfo $current) use ($group, $prefix) { |
|
| 423 | + if (!$current->isFile()) { |
|
| 424 | 424 | return false; |
| 425 | 425 | } |
| 426 | 426 | |
@@ -432,7 +432,7 @@ discard block |
||
| 432 | 432 | |
| 433 | 433 | return str_contains( |
| 434 | 434 | $current->getPathname(), |
| 435 | - DIRECTORY_SEPARATOR . $group . DIRECTORY_SEPARATOR, |
|
| 435 | + DIRECTORY_SEPARATOR.$group.DIRECTORY_SEPARATOR, |
|
| 436 | 436 | ); |
| 437 | 437 | } |
| 438 | 438 | ); |
@@ -466,23 +466,23 @@ discard block |
||
| 466 | 466 | */ |
| 467 | 467 | protected function getDirFileInfo(string $sourceDir, bool $topLevelOnly = true, bool $_recursion = false) |
| 468 | 468 | { |
| 469 | - static $_filedata = []; |
|
| 469 | + static $_filedata = [ ]; |
|
| 470 | 470 | $relativePath = $sourceDir; |
| 471 | 471 | |
| 472 | 472 | if ($fp = @opendir($sourceDir)) { |
| 473 | 473 | // réinitialise le tableau et s'assure que $source_dir a une barre oblique à la fin de l'appel initial |
| 474 | 474 | if ($_recursion === false) { |
| 475 | - $_filedata = []; |
|
| 476 | - $sourceDir = rtrim(realpath($sourceDir) ?: $sourceDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; |
|
| 475 | + $_filedata = [ ]; |
|
| 476 | + $sourceDir = rtrim(realpath($sourceDir) ?: $sourceDir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; |
|
| 477 | 477 | } |
| 478 | 478 | |
| 479 | 479 | // Utilisé pour être foreach (scandir($source_dir, 1) comme $file), mais scandir() n'est tout simplement pas aussi rapide |
| 480 | 480 | while (false !== ($file = readdir($fp))) { |
| 481 | - if (is_dir($sourceDir . $file) && $file[0] !== '.' && $topLevelOnly === false) { |
|
| 482 | - $this->getDirFileInfo($sourceDir . $file . DIRECTORY_SEPARATOR, $topLevelOnly, true); |
|
| 483 | - } elseif (! is_dir($sourceDir . $file) && $file[0] !== '.') { |
|
| 484 | - $_filedata[$file] = $this->getFileInfo($sourceDir . $file); |
|
| 485 | - $_filedata[$file]['relative_path'] = $relativePath; |
|
| 481 | + if (is_dir($sourceDir.$file) && $file[ 0 ] !== '.' && $topLevelOnly === false) { |
|
| 482 | + $this->getDirFileInfo($sourceDir.$file.DIRECTORY_SEPARATOR, $topLevelOnly, true); |
|
| 483 | + } elseif (!is_dir($sourceDir.$file) && $file[ 0 ] !== '.') { |
|
| 484 | + $_filedata[ $file ] = $this->getFileInfo($sourceDir.$file); |
|
| 485 | + $_filedata[ $file ][ 'relative_path' ] = $relativePath; |
|
| 486 | 486 | } |
| 487 | 487 | } |
| 488 | 488 | |
@@ -504,9 +504,9 @@ discard block |
||
| 504 | 504 | * |
| 505 | 505 | * @return array|false |
| 506 | 506 | */ |
| 507 | - protected function getFileInfo(string $file, $returnedValues = ['name', 'server_path', 'size', 'date']) |
|
| 507 | + protected function getFileInfo(string $file, $returnedValues = [ 'name', 'server_path', 'size', 'date' ]) |
|
| 508 | 508 | { |
| 509 | - if (! is_file($file)) { |
|
| 509 | + if (!is_file($file)) { |
|
| 510 | 510 | return false; |
| 511 | 511 | } |
| 512 | 512 | |
@@ -514,40 +514,40 @@ discard block |
||
| 514 | 514 | $returnedValues = explode(',', $returnedValues); |
| 515 | 515 | } |
| 516 | 516 | |
| 517 | - $fileInfo = []; |
|
| 517 | + $fileInfo = [ ]; |
|
| 518 | 518 | |
| 519 | 519 | foreach ($returnedValues as $key) { |
| 520 | 520 | switch ($key) { |
| 521 | 521 | case 'name': |
| 522 | - $fileInfo['name'] = basename($file); |
|
| 522 | + $fileInfo[ 'name' ] = basename($file); |
|
| 523 | 523 | break; |
| 524 | 524 | |
| 525 | 525 | case 'server_path': |
| 526 | - $fileInfo['server_path'] = $file; |
|
| 526 | + $fileInfo[ 'server_path' ] = $file; |
|
| 527 | 527 | break; |
| 528 | 528 | |
| 529 | 529 | case 'size': |
| 530 | - $fileInfo['size'] = filesize($file); |
|
| 530 | + $fileInfo[ 'size' ] = filesize($file); |
|
| 531 | 531 | break; |
| 532 | 532 | |
| 533 | 533 | case 'date': |
| 534 | - $fileInfo['date'] = filemtime($file); |
|
| 534 | + $fileInfo[ 'date' ] = filemtime($file); |
|
| 535 | 535 | break; |
| 536 | 536 | |
| 537 | 537 | case 'readable': |
| 538 | - $fileInfo['readable'] = is_readable($file); |
|
| 538 | + $fileInfo[ 'readable' ] = is_readable($file); |
|
| 539 | 539 | break; |
| 540 | 540 | |
| 541 | 541 | case 'writable': |
| 542 | - $fileInfo['writable'] = is_writable($file); |
|
| 542 | + $fileInfo[ 'writable' ] = is_writable($file); |
|
| 543 | 543 | break; |
| 544 | 544 | |
| 545 | 545 | case 'executable': |
| 546 | - $fileInfo['executable'] = is_executable($file); |
|
| 546 | + $fileInfo[ 'executable' ] = is_executable($file); |
|
| 547 | 547 | break; |
| 548 | 548 | |
| 549 | 549 | case 'fileperms': |
| 550 | - $fileInfo['fileperms'] = fileperms($file); |
|
| 550 | + $fileInfo[ 'fileperms' ] = fileperms($file); |
|
| 551 | 551 | break; |
| 552 | 552 | } |
| 553 | 553 | } |
@@ -240,7 +240,7 @@ |
||
| 240 | 240 | { |
| 241 | 241 | $this->ensureValidType($values, self::CHECK_KEY); |
| 242 | 242 | |
| 243 | - $restore = null; |
|
| 243 | + $restore = null; |
|
| 244 | 244 | if ($ttl !== null) { |
| 245 | 245 | $restore = $this->getConfig('duration'); |
| 246 | 246 | $this->setConfig('duration', $ttl); |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | */ |
| 62 | 62 | protected array $_defaultConfig = [ |
| 63 | 63 | 'duration' => 3600, |
| 64 | - 'groups' => [], |
|
| 64 | + 'groups' => [ ], |
|
| 65 | 65 | 'prefix' => 'blitz_', |
| 66 | 66 | 'warnOnWriteFailures' => true, |
| 67 | 67 | ]; |
@@ -82,20 +82,20 @@ discard block |
||
| 82 | 82 | * |
| 83 | 83 | * @return bool Vrai si le moteur a été initialisé avec succès, faux sinon |
| 84 | 84 | */ |
| 85 | - public function init(array $config = []): bool |
|
| 85 | + public function init(array $config = [ ]): bool |
|
| 86 | 86 | { |
| 87 | - if (isset($config['prefix'])) { |
|
| 88 | - $config['prefix'] = str_replace(' ', '-', strtolower($config['prefix'])); |
|
| 87 | + if (isset($config[ 'prefix' ])) { |
|
| 88 | + $config[ 'prefix' ] = str_replace(' ', '-', strtolower($config[ 'prefix' ])); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | $this->setConfig($config); |
| 92 | 92 | |
| 93 | - if (! empty($this->_config['groups'])) { |
|
| 94 | - sort($this->_config['groups']); |
|
| 95 | - $this->_groupPrefix = str_repeat('%s_', count($this->_config['groups'])); |
|
| 93 | + if (!empty($this->_config[ 'groups' ])) { |
|
| 94 | + sort($this->_config[ 'groups' ]); |
|
| 95 | + $this->_groupPrefix = str_repeat('%s_', count($this->_config[ 'groups' ])); |
|
| 96 | 96 | } |
| 97 | - if (! is_numeric($this->_config['duration'])) { |
|
| 98 | - $this->_config['duration'] = strtotime($this->_config['duration']) - time(); |
|
| 97 | + if (!is_numeric($this->_config[ 'duration' ])) { |
|
| 98 | + $this->_config[ 'duration' ] = strtotime($this->_config[ 'duration' ]) - time(); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | return true; |
@@ -116,13 +116,13 @@ discard block |
||
| 116 | 116 | */ |
| 117 | 117 | public function ensureValidKey(string $key): void |
| 118 | 118 | { |
| 119 | - if (! is_string($key) || $key === '') { |
|
| 119 | + if (!is_string($key) || $key === '') { |
|
| 120 | 120 | throw new InvalidArgumentException('Une clé de cache doit être une chaîne non vide.'); |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | $reserved = self::$reservedCharacters; |
| 124 | 124 | if ($reserved && strpbrk($key, $reserved) !== false) { |
| 125 | - throw new InvalidArgumentException('La clé de cache contient des caractères réservés ' . $reserved); |
|
| 125 | + throw new InvalidArgumentException('La clé de cache contient des caractères réservés '.$reserved); |
|
| 126 | 126 | } |
| 127 | 127 | } |
| 128 | 128 | |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | * @return mixed Si la clé est trouvée : les données en cache. |
| 172 | 172 | * Si la clé n'est pas trouvée, la valeur renvoyée par le callable. |
| 173 | 173 | */ |
| 174 | - public function remember(string $key, callable|DateInterval|int|null $ttl, ?callable $callable = null): mixed |
|
| 174 | + public function remember(string $key, callable | DateInterval | int | null $ttl, ?callable $callable = null): mixed |
|
| 175 | 175 | { |
| 176 | 176 | if (is_callable($ttl)) { |
| 177 | 177 | $callable = $ttl; |
@@ -214,10 +214,10 @@ discard block |
||
| 214 | 214 | { |
| 215 | 215 | $this->ensureValidType($keys); |
| 216 | 216 | |
| 217 | - $results = []; |
|
| 217 | + $results = [ ]; |
|
| 218 | 218 | |
| 219 | 219 | foreach ($keys as $key) { |
| 220 | - $results[$key] = $this->get($key, $default); |
|
| 220 | + $results[ $key ] = $this->get($key, $default); |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | return $results; |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | * @throws InvalidArgumentException Si $values n'est ni un tableau ni un Traversable, |
| 237 | 237 | * ou si l'une des valeurs $ n'est pas une valeur légale. |
| 238 | 238 | */ |
| 239 | - public function setMultiple(iterable $values, DateInterval|int|null $ttl = null): bool |
|
| 239 | + public function setMultiple(iterable $values, DateInterval | int | null $ttl = null): bool |
|
| 240 | 240 | { |
| 241 | 241 | $this->ensureValidType($values, self::CHECK_KEY); |
| 242 | 242 | |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | |
| 257 | 257 | return true; |
| 258 | 258 | } finally { |
| 259 | - if($restore !== null) { |
|
| 259 | + if ($restore !== null) { |
|
| 260 | 260 | $this->setConfig('duration', $restore); |
| 261 | 261 | } |
| 262 | 262 | } |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | $result = true; |
| 284 | 284 | |
| 285 | 285 | foreach ($keys as $key) { |
| 286 | - if (! $this->delete($key)) { |
|
| 286 | + if (!$this->delete($key)) { |
|
| 287 | 287 | $result = false; |
| 288 | 288 | } |
| 289 | 289 | } |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | * |
| 323 | 323 | * @return bool Vrai en cas de succès et faux en cas d'échec. |
| 324 | 324 | */ |
| 325 | - abstract public function set(string $key, mixed $value, DateInterval|int|null $ttl = null): bool; |
|
| 325 | + abstract public function set(string $key, mixed $value, DateInterval | int | null $ttl = null): bool; |
|
| 326 | 326 | |
| 327 | 327 | /** |
| 328 | 328 | * {@inheritDoc} |
@@ -379,7 +379,7 @@ discard block |
||
| 379 | 379 | */ |
| 380 | 380 | public function groups(): array |
| 381 | 381 | { |
| 382 | - return $this->_config['groups']; |
|
| 382 | + return $this->_config[ 'groups' ]; |
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | /** |
@@ -404,7 +404,7 @@ discard block |
||
| 404 | 404 | } |
| 405 | 405 | $key = preg_replace('/[\s]+/', '_', $key); |
| 406 | 406 | |
| 407 | - return $this->_config['prefix'] . $prefix . $key; |
|
| 407 | + return $this->_config[ 'prefix' ].$prefix.$key; |
|
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 410 | /** |
@@ -426,10 +426,10 @@ discard block |
||
| 426 | 426 | * @param DateInterval|int|null $ttl La valeur TTL de cet élément. Si null est envoyé, |
| 427 | 427 | * La durée par défaut du conducteur sera utilisée. |
| 428 | 428 | */ |
| 429 | - protected function duration(DateInterval|int|null $ttl): int |
|
| 429 | + protected function duration(DateInterval | int | null $ttl): int |
|
| 430 | 430 | { |
| 431 | 431 | if ($ttl === null) { |
| 432 | - return $this->_config['duration']; |
|
| 432 | + return $this->_config[ 'duration' ]; |
|
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | if (is_int($ttl)) { |
@@ -272,7 +272,7 @@ |
||
| 272 | 272 | */ |
| 273 | 273 | public function clear(): bool |
| 274 | 274 | { |
| 275 | - if ($this->getConfig('clearUsesFlushDb')) { |
|
| 275 | + if ($this->getConfig('clearUsesFlushDb')) { |
|
| 276 | 276 | $this->_Redis->flushDB(false); |
| 277 | 277 | |
| 278 | 278 | return true; |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | protected array $_defaultConfig = [ |
| 48 | 48 | 'database' => 0, |
| 49 | 49 | 'duration' => 3600, |
| 50 | - 'groups' => [], |
|
| 50 | + 'groups' => [ ], |
|
| 51 | 51 | 'password' => false, |
| 52 | 52 | 'persistent' => true, |
| 53 | 53 | 'port' => 6379, |
@@ -63,14 +63,14 @@ discard block |
||
| 63 | 63 | /** |
| 64 | 64 | * {@inheritDoc} |
| 65 | 65 | */ |
| 66 | - public function init(array $config = []): bool |
|
| 66 | + public function init(array $config = [ ]): bool |
|
| 67 | 67 | { |
| 68 | - if (! extension_loaded('redis')) { |
|
| 68 | + if (!extension_loaded('redis')) { |
|
| 69 | 69 | throw new RuntimeException('L\'extension `redis` doit être activée pour utiliser RedisHandler.'); |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - if (! empty($config['host'])) { |
|
| 73 | - $config['server'] = $config['host']; |
|
| 72 | + if (!empty($config[ 'host' ])) { |
|
| 73 | + $config[ 'server' ] = $config[ 'host' ]; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | parent::init($config); |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | */ |
| 86 | 86 | protected function _connect(): bool |
| 87 | 87 | { |
| 88 | - $tls = $this->_config['tls'] === true ? 'tls://' : ''; |
|
| 88 | + $tls = $this->_config[ 'tls' ] === true ? 'tls://' : ''; |
|
| 89 | 89 | |
| 90 | 90 | $map = [ |
| 91 | 91 | 'ssl_ca' => 'cafile', |
@@ -93,37 +93,37 @@ discard block |
||
| 93 | 93 | 'ssl_cert' => 'local_cert', |
| 94 | 94 | ]; |
| 95 | 95 | |
| 96 | - $ssl = []; |
|
| 96 | + $ssl = [ ]; |
|
| 97 | 97 | foreach ($map as $key => $context) { |
| 98 | - if (!empty($this->_config[$key])) { |
|
| 99 | - $ssl[$context] = $this->_config[$key]; |
|
| 98 | + if (!empty($this->_config[ $key ])) { |
|
| 99 | + $ssl[ $context ] = $this->_config[ $key ]; |
|
| 100 | 100 | } |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | try { |
| 104 | 104 | $this->_Redis = $this->_createRedisInstance(); |
| 105 | - if (! empty($this->_config['unix_socket'])) { |
|
| 106 | - $return = $this->_Redis->connect($this->_config['unix_socket']); |
|
| 107 | - } elseif (empty($this->_config['persistent'])) { |
|
| 108 | - $return = $this->_connectTransient($tls . $this->_config['server'], $ssl); |
|
| 105 | + if (!empty($this->_config[ 'unix_socket' ])) { |
|
| 106 | + $return = $this->_Redis->connect($this->_config[ 'unix_socket' ]); |
|
| 107 | + } elseif (empty($this->_config[ 'persistent' ])) { |
|
| 108 | + $return = $this->_connectTransient($tls.$this->_config[ 'server' ], $ssl); |
|
| 109 | 109 | } else { |
| 110 | - $return = $this->_connectPersistent($tls . $this->_config['server'], $ssl); |
|
| 110 | + $return = $this->_connectPersistent($tls.$this->_config[ 'server' ], $ssl); |
|
| 111 | 111 | } |
| 112 | 112 | } catch (RedisException $e) { |
| 113 | 113 | if (function_exists('logger')) { |
| 114 | 114 | $logger = logger(); |
| 115 | 115 | if (is_object($logger) && method_exists($logger, 'error')) { |
| 116 | - $logger->error('RedisEngine n\'a pas pu se connecter. Erreur: ' . $e->getMessage()); |
|
| 116 | + $logger->error('RedisEngine n\'a pas pu se connecter. Erreur: '.$e->getMessage()); |
|
| 117 | 117 | } |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | return false; |
| 121 | 121 | } |
| 122 | - if ($return && $this->_config['password']) { |
|
| 123 | - $return = $this->_Redis->auth($this->_config['password']); |
|
| 122 | + if ($return && $this->_config[ 'password' ]) { |
|
| 123 | + $return = $this->_Redis->auth($this->_config[ 'password' ]); |
|
| 124 | 124 | } |
| 125 | 125 | if ($return) { |
| 126 | - return $this->_Redis->select((int) $this->_config['database']); |
|
| 126 | + return $this->_Redis->select((int) $this->_config[ 'database' ]); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | return $return; |
@@ -136,22 +136,22 @@ discard block |
||
| 136 | 136 | */ |
| 137 | 137 | protected function _connectTransient(string $server, array $ssl): bool |
| 138 | 138 | { |
| 139 | - if ($ssl === []) { |
|
| 139 | + if ($ssl === [ ]) { |
|
| 140 | 140 | return $this->_Redis->connect( |
| 141 | 141 | $server, |
| 142 | - (int) $this->_config['port'], |
|
| 143 | - (int) $this->_config['timeout'], |
|
| 142 | + (int) $this->_config[ 'port' ], |
|
| 143 | + (int) $this->_config[ 'timeout' ], |
|
| 144 | 144 | ); |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | return $this->_Redis->connect( |
| 148 | 148 | $server, |
| 149 | - (int) $this->_config['port'], |
|
| 150 | - (int) $this->_config['timeout'], |
|
| 149 | + (int) $this->_config[ 'port' ], |
|
| 150 | + (int) $this->_config[ 'timeout' ], |
|
| 151 | 151 | null, |
| 152 | 152 | 0, |
| 153 | 153 | 0.0, |
| 154 | - ['ssl' => $ssl], |
|
| 154 | + [ 'ssl' => $ssl ], |
|
| 155 | 155 | ); |
| 156 | 156 | } |
| 157 | 157 | |
@@ -162,32 +162,32 @@ discard block |
||
| 162 | 162 | */ |
| 163 | 163 | protected function _connectPersistent(string $server, array $ssl): bool |
| 164 | 164 | { |
| 165 | - $persistentId = $this->_config['port'] . $this->_config['timeout'] . $this->_config['database']; |
|
| 165 | + $persistentId = $this->_config[ 'port' ].$this->_config[ 'timeout' ].$this->_config[ 'database' ]; |
|
| 166 | 166 | |
| 167 | - if ($ssl === []) { |
|
| 167 | + if ($ssl === [ ]) { |
|
| 168 | 168 | return $this->_Redis->pconnect( |
| 169 | 169 | $server, |
| 170 | - (int) $this->_config['port'], |
|
| 171 | - (int) $this->_config['timeout'], |
|
| 170 | + (int) $this->_config[ 'port' ], |
|
| 171 | + (int) $this->_config[ 'timeout' ], |
|
| 172 | 172 | $persistentId, |
| 173 | 173 | ); |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | return $this->_Redis->pconnect( |
| 177 | 177 | $server, |
| 178 | - (int) $this->_config['port'], |
|
| 179 | - (int) $this->_config['timeout'], |
|
| 178 | + (int) $this->_config[ 'port' ], |
|
| 179 | + (int) $this->_config[ 'timeout' ], |
|
| 180 | 180 | $persistentId, |
| 181 | 181 | 0, |
| 182 | 182 | 0.0, |
| 183 | - ['ssl' => $ssl], |
|
| 183 | + [ 'ssl' => $ssl ], |
|
| 184 | 184 | ); |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | /** |
| 188 | 188 | * {@inheritDoc} |
| 189 | 189 | */ |
| 190 | - public function set(string $key, mixed $value, DateInterval|int|null $ttl = null): bool |
|
| 190 | + public function set(string $key, mixed $value, DateInterval | int | null $ttl = null): bool |
|
| 191 | 191 | { |
| 192 | 192 | $key = $this->_key($key); |
| 193 | 193 | $value = $this->serialize($value); |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | */ |
| 219 | 219 | public function increment(string $key, int $offset = 1) |
| 220 | 220 | { |
| 221 | - $duration = $this->_config['duration']; |
|
| 221 | + $duration = $this->_config[ 'duration' ]; |
|
| 222 | 222 | $key = $this->_key($key); |
| 223 | 223 | |
| 224 | 224 | $value = $this->_Redis->incrBy($key, $offset); |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | */ |
| 235 | 235 | public function decrement(string $key, int $offset = 1) |
| 236 | 236 | { |
| 237 | - $duration = $this->_config['duration']; |
|
| 237 | + $duration = $this->_config[ 'duration' ]; |
|
| 238 | 238 | $key = $this->_key($key); |
| 239 | 239 | |
| 240 | 240 | $value = $this->_Redis->decrBy($key, $offset); |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | |
| 283 | 283 | $isAllDeleted = true; |
| 284 | 284 | $iterator = null; |
| 285 | - $pattern = $this->_config['prefix'] . '*'; |
|
| 285 | + $pattern = $this->_config[ 'prefix' ].'*'; |
|
| 286 | 286 | |
| 287 | 287 | while (true) { |
| 288 | 288 | $keys = $this->_Redis->scan($iterator, $pattern); |
@@ -315,17 +315,17 @@ discard block |
||
| 315 | 315 | |
| 316 | 316 | $isAllDeleted = true; |
| 317 | 317 | $iterator = null; |
| 318 | - $pattern = $this->_config['prefix'] . '*'; |
|
| 318 | + $pattern = $this->_config[ 'prefix' ].'*'; |
|
| 319 | 319 | |
| 320 | 320 | while (true) { |
| 321 | - $keys = $this->_Redis->scan($iterator, $pattern, (int)$this->_config['scanCount']); |
|
| 321 | + $keys = $this->_Redis->scan($iterator, $pattern, (int) $this->_config[ 'scanCount' ]); |
|
| 322 | 322 | |
| 323 | 323 | if ($keys === false) { |
| 324 | 324 | break; |
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | foreach ($keys as $key) { |
| 328 | - $isDeleted = ((int)$this->_Redis->del($key) > 0); |
|
| 328 | + $isDeleted = ((int) $this->_Redis->del($key) > 0); |
|
| 329 | 329 | $isAllDeleted = $isAllDeleted && $isDeleted; |
| 330 | 330 | } |
| 331 | 331 | } |
@@ -340,11 +340,11 @@ discard block |
||
| 340 | 340 | */ |
| 341 | 341 | public function add(string $key, mixed $value): bool |
| 342 | 342 | { |
| 343 | - $duration = $this->_config['duration']; |
|
| 343 | + $duration = $this->_config[ 'duration' ]; |
|
| 344 | 344 | $key = $this->_key($key); |
| 345 | 345 | $value = $this->serialize($value); |
| 346 | 346 | |
| 347 | - return (bool) ($this->_Redis->set($key, $value, ['nx', 'ex' => $duration])); |
|
| 347 | + return (bool) ($this->_Redis->set($key, $value, [ 'nx', 'ex' => $duration ])); |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | /** |
@@ -360,15 +360,15 @@ discard block |
||
| 360 | 360 | */ |
| 361 | 361 | public function groups(): array |
| 362 | 362 | { |
| 363 | - $result = []; |
|
| 363 | + $result = [ ]; |
|
| 364 | 364 | |
| 365 | - foreach ($this->_config['groups'] as $group) { |
|
| 366 | - $value = $this->_Redis->get($this->_config['prefix'] . $group); |
|
| 367 | - if (! $value) { |
|
| 365 | + foreach ($this->_config[ 'groups' ] as $group) { |
|
| 366 | + $value = $this->_Redis->get($this->_config[ 'prefix' ].$group); |
|
| 367 | + if (!$value) { |
|
| 368 | 368 | $value = $this->serialize(1); |
| 369 | - $this->_Redis->set($this->_config['prefix'] . $group, $value); |
|
| 369 | + $this->_Redis->set($this->_config[ 'prefix' ].$group, $value); |
|
| 370 | 370 | } |
| 371 | - $result[] = $group . $value; |
|
| 371 | + $result[ ] = $group.$value; |
|
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | return $result; |
@@ -379,7 +379,7 @@ discard block |
||
| 379 | 379 | */ |
| 380 | 380 | public function clearGroup(string $group): bool |
| 381 | 381 | { |
| 382 | - return (bool) $this->_Redis->incr($this->_config['prefix'] . $group); |
|
| 382 | + return (bool) $this->_Redis->incr($this->_config[ 'prefix' ].$group); |
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | /** |
@@ -424,7 +424,7 @@ discard block |
||
| 424 | 424 | */ |
| 425 | 425 | public function __destruct() |
| 426 | 426 | { |
| 427 | - if (empty($this->_config['persistent']) && $this->_Redis instanceof Redis) { |
|
| 427 | + if (empty($this->_config[ 'persistent' ]) && $this->_Redis instanceof Redis) { |
|
| 428 | 428 | $this->_Redis->close(); |
| 429 | 429 | } |
| 430 | 430 | } |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | /** |
| 32 | 32 | * {@inheritDoc} |
| 33 | 33 | */ |
| 34 | - public function init(array $config = []): bool |
|
| 34 | + public function init(array $config = [ ]): bool |
|
| 35 | 35 | { |
| 36 | 36 | return true; |
| 37 | 37 | } |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | /** |
| 40 | 40 | * {@inheritDoc} |
| 41 | 41 | */ |
| 42 | - public function set(string $key, mixed $value, DateInterval|int|null $ttl = null): bool |
|
| 42 | + public function set(string $key, mixed $value, DateInterval | int | null $ttl = null): bool |
|
| 43 | 43 | { |
| 44 | 44 | return true; |
| 45 | 45 | } |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | /** |
| 48 | 48 | * {@inheritDoc} |
| 49 | 49 | */ |
| 50 | - public function setMultiple(iterable $values, DateInterval|int|null $ttl = null): bool |
|
| 50 | + public function setMultiple(iterable $values, DateInterval | int | null $ttl = null): bool |
|
| 51 | 51 | { |
| 52 | 52 | return true; |
| 53 | 53 | } |
@@ -65,10 +65,10 @@ discard block |
||
| 65 | 65 | */ |
| 66 | 66 | public function getMultiple(iterable $keys, mixed $default = null): iterable |
| 67 | 67 | { |
| 68 | - $result = []; |
|
| 68 | + $result = [ ]; |
|
| 69 | 69 | |
| 70 | 70 | foreach ($keys as $key) { |
| 71 | - $result[$key] = $default; |
|
| 71 | + $result[ $key ] = $default; |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | return $result; |
@@ -88,7 +88,7 @@ |
||
| 88 | 88 | if ($this->get($key) === null) { |
| 89 | 89 | $this->set($key, 0); |
| 90 | 90 | |
| 91 | - return 0; |
|
| 91 | + return 0; |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | $key = $this->_key($key); |
@@ -30,16 +30,16 @@ discard block |
||
| 30 | 30 | * |
| 31 | 31 | * Structuré comme [clé => [exp => expiration, val => valeur]] |
| 32 | 32 | */ |
| 33 | - protected array $data = []; |
|
| 33 | + protected array $data = [ ]; |
|
| 34 | 34 | |
| 35 | 35 | /** |
| 36 | 36 | * {@inheritDoc} |
| 37 | 37 | */ |
| 38 | - public function set(string $key, mixed $value, DateInterval|int|null $ttl = null): bool |
|
| 38 | + public function set(string $key, mixed $value, DateInterval | int | null $ttl = null): bool |
|
| 39 | 39 | { |
| 40 | 40 | $key = $this->_key($key); |
| 41 | 41 | $expires = time() + $this->duration($ttl); |
| 42 | - $this->data[$key] = ['exp' => $expires, 'val' => $value]; |
|
| 42 | + $this->data[ $key ] = [ 'exp' => $expires, 'val' => $value ]; |
|
| 43 | 43 | |
| 44 | 44 | return true; |
| 45 | 45 | } |
@@ -50,20 +50,20 @@ discard block |
||
| 50 | 50 | public function get(string $key, mixed $default = null): mixed |
| 51 | 51 | { |
| 52 | 52 | $key = $this->_key($key); |
| 53 | - if (! isset($this->data[$key])) { |
|
| 53 | + if (!isset($this->data[ $key ])) { |
|
| 54 | 54 | return $default; |
| 55 | 55 | } |
| 56 | - $data = $this->data[$key]; |
|
| 56 | + $data = $this->data[ $key ]; |
|
| 57 | 57 | |
| 58 | 58 | // Verifie l'expiration |
| 59 | 59 | $now = time(); |
| 60 | - if ($data['exp'] <= $now) { |
|
| 61 | - unset($this->data[$key]); |
|
| 60 | + if ($data[ 'exp' ] <= $now) { |
|
| 61 | + unset($this->data[ $key ]); |
|
| 62 | 62 | |
| 63 | 63 | return $default; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - return $data['val']; |
|
| 66 | + return $data[ 'val' ]; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -75,9 +75,9 @@ discard block |
||
| 75 | 75 | $this->set($key, 0); |
| 76 | 76 | } |
| 77 | 77 | $key = $this->_key($key); |
| 78 | - $this->data[$key]['val'] += $offset; |
|
| 78 | + $this->data[ $key ][ 'val' ] += $offset; |
|
| 79 | 79 | |
| 80 | - return $this->data[$key]['val']; |
|
| 80 | + return $this->data[ $key ][ 'val' ]; |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | /** |
@@ -92,9 +92,9 @@ discard block |
||
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | $key = $this->_key($key); |
| 95 | - $this->data[$key]['val'] -= $offset; |
|
| 95 | + $this->data[ $key ][ 'val' ] -= $offset; |
|
| 96 | 96 | |
| 97 | - return $this->data[$key]['val']; |
|
| 97 | + return $this->data[ $key ][ 'val' ]; |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | /** |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | public function delete(string $key): bool |
| 104 | 104 | { |
| 105 | 105 | $key = $this->_key($key); |
| 106 | - unset($this->data[$key]); |
|
| 106 | + unset($this->data[ $key ]); |
|
| 107 | 107 | |
| 108 | 108 | return true; |
| 109 | 109 | } |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | */ |
| 114 | 114 | public function clear(): bool |
| 115 | 115 | { |
| 116 | - $this->data = []; |
|
| 116 | + $this->data = [ ]; |
|
| 117 | 117 | |
| 118 | 118 | return true; |
| 119 | 119 | } |
@@ -123,15 +123,15 @@ discard block |
||
| 123 | 123 | */ |
| 124 | 124 | public function groups(): array |
| 125 | 125 | { |
| 126 | - $result = []; |
|
| 126 | + $result = [ ]; |
|
| 127 | 127 | |
| 128 | - foreach ($this->_config['groups'] as $group) { |
|
| 129 | - $key = $this->_config['prefix'] . $group; |
|
| 130 | - if (! isset($this->data[$key])) { |
|
| 131 | - $this->data[$key] = ['exp' => PHP_INT_MAX, 'val' => 1]; |
|
| 128 | + foreach ($this->_config[ 'groups' ] as $group) { |
|
| 129 | + $key = $this->_config[ 'prefix' ].$group; |
|
| 130 | + if (!isset($this->data[ $key ])) { |
|
| 131 | + $this->data[ $key ] = [ 'exp' => PHP_INT_MAX, 'val' => 1 ]; |
|
| 132 | 132 | } |
| 133 | - $value = $this->data[$key]['val']; |
|
| 134 | - $result[] = $group . $value; |
|
| 133 | + $value = $this->data[ $key ][ 'val' ]; |
|
| 134 | + $result[ ] = $group.$value; |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | return $result; |
@@ -142,9 +142,9 @@ discard block |
||
| 142 | 142 | */ |
| 143 | 143 | public function clearGroup(string $group): bool |
| 144 | 144 | { |
| 145 | - $key = $this->_config['prefix'] . $group; |
|
| 146 | - if (isset($this->data[$key])) { |
|
| 147 | - $this->data[$key]['val']++; |
|
| 145 | + $key = $this->_config[ 'prefix' ].$group; |
|
| 146 | + if (isset($this->data[ $key ])) { |
|
| 147 | + $this->data[ $key ][ 'val' ]++; |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | return true; |
@@ -334,7 +334,7 @@ |
||
| 334 | 334 | return array_fill_keys(array_keys($cacheKeys), $default); |
| 335 | 335 | } |
| 336 | 336 | |
| 337 | - $return = []; |
|
| 337 | + $return = []; |
|
| 338 | 338 | foreach ($cacheKeys as $original => $prefixed) { |
| 339 | 339 | $return[$original] = $values[$prefixed] ?? $default; |
| 340 | 340 | } |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | protected array $_defaultConfig = [ |
| 59 | 59 | 'compress' => false, |
| 60 | 60 | 'duration' => 3600, |
| 61 | - 'groups' => [], |
|
| 61 | + 'groups' => [ ], |
|
| 62 | 62 | 'host' => null, |
| 63 | 63 | 'username' => null, |
| 64 | 64 | 'password' => null, |
@@ -66,8 +66,8 @@ discard block |
||
| 66 | 66 | 'port' => null, |
| 67 | 67 | 'prefix' => 'blitz_', |
| 68 | 68 | 'serialize' => 'php', |
| 69 | - 'servers' => ['127.0.0.1'], |
|
| 70 | - 'options' => [], |
|
| 69 | + 'servers' => [ '127.0.0.1' ], |
|
| 70 | + 'options' => [ ], |
|
| 71 | 71 | ]; |
| 72 | 72 | |
| 73 | 73 | /** |
@@ -75,19 +75,19 @@ discard block |
||
| 75 | 75 | * |
| 76 | 76 | * Memcached doit être compilé avec JSON et le support igbinary pour utiliser ces moteurs |
| 77 | 77 | */ |
| 78 | - protected array $_serializers = []; |
|
| 78 | + protected array $_serializers = [ ]; |
|
| 79 | 79 | |
| 80 | 80 | /** |
| 81 | 81 | * @var list<string> |
| 82 | 82 | */ |
| 83 | - protected array $_compiledGroupNames = []; |
|
| 83 | + protected array $_compiledGroupNames = [ ]; |
|
| 84 | 84 | |
| 85 | 85 | /** |
| 86 | 86 | * {@inheritDoc} |
| 87 | 87 | */ |
| 88 | - public function init(array $config = []): bool |
|
| 88 | + public function init(array $config = [ ]): bool |
|
| 89 | 89 | { |
| 90 | - if (! extension_loaded('memcached')) { |
|
| 90 | + if (!extension_loaded('memcached')) { |
|
| 91 | 91 | throw new RuntimeException('L\'extension `memcached` doit être activée pour utiliser MemcachedHandler.'); |
| 92 | 92 | } |
| 93 | 93 | |
@@ -97,25 +97,25 @@ discard block |
||
| 97 | 97 | 'php' => BaseMemcached::SERIALIZER_PHP, |
| 98 | 98 | ]; |
| 99 | 99 | if (defined('Memcached::HAVE_MSGPACK')) { |
| 100 | - $this->_serializers['msgpack'] = BaseMemcached::SERIALIZER_MSGPACK; |
|
| 100 | + $this->_serializers[ 'msgpack' ] = BaseMemcached::SERIALIZER_MSGPACK; |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | parent::init($config); |
| 104 | 104 | |
| 105 | - if (! empty($config['host'])) { |
|
| 106 | - if (empty($config['port'])) { |
|
| 107 | - $config['servers'] = [$config['host']]; |
|
| 105 | + if (!empty($config[ 'host' ])) { |
|
| 106 | + if (empty($config[ 'port' ])) { |
|
| 107 | + $config[ 'servers' ] = [ $config[ 'host' ] ]; |
|
| 108 | 108 | } else { |
| 109 | - $config['servers'] = [sprintf('%s:%d', $config['host'], $config['port'])]; |
|
| 109 | + $config[ 'servers' ] = [ sprintf('%s:%d', $config[ 'host' ], $config[ 'port' ]) ]; |
|
| 110 | 110 | } |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - if (isset($config['servers'])) { |
|
| 114 | - $this->setConfig('servers', $config['servers'], false); |
|
| 113 | + if (isset($config[ 'servers' ])) { |
|
| 114 | + $this->setConfig('servers', $config[ 'servers' ], false); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - if (! is_array($this->_config['servers'])) { |
|
| 118 | - $this->_config['servers'] = [$this->_config['servers']]; |
|
| 117 | + if (!is_array($this->_config[ 'servers' ])) { |
|
| 118 | + $this->_config[ 'servers' ] = [ $this->_config[ 'servers' ] ]; |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** @psalm-suppress RedundantPropertyInitializationCheck */ |
@@ -123,8 +123,8 @@ discard block |
||
| 123 | 123 | return true; |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - if ($this->_config['persistent']) { |
|
| 127 | - $this->_Memcached = new BaseMemcached($this->_config['persistent']); |
|
| 126 | + if ($this->_config[ 'persistent' ]) { |
|
| 127 | + $this->_Memcached = new BaseMemcached($this->_config[ 'persistent' ]); |
|
| 128 | 128 | } else { |
| 129 | 129 | $this->_Memcached = new BaseMemcached(); |
| 130 | 130 | } |
@@ -134,10 +134,10 @@ discard block |
||
| 134 | 134 | if ($serverList) { |
| 135 | 135 | if ($this->_Memcached->isPersistent()) { |
| 136 | 136 | foreach ($serverList as $server) { |
| 137 | - if (! in_array($server['host'] . ':' . $server['port'], $this->_config['servers'], true)) { |
|
| 137 | + if (!in_array($server[ 'host' ].':'.$server[ 'port' ], $this->_config[ 'servers' ], true)) { |
|
| 138 | 138 | throw new InvalidArgumentException( |
| 139 | - 'Configuration du cache invalide. Plusieurs configurations de cache persistant sont détectées' . |
|
| 140 | - ' avec des valeurs `servers` différentes. `valeurs` des serveurs pour les configurations de cache persistant' . |
|
| 139 | + 'Configuration du cache invalide. Plusieurs configurations de cache persistant sont détectées'. |
|
| 140 | + ' avec des valeurs `servers` différentes. `valeurs` des serveurs pour les configurations de cache persistant'. |
|
| 141 | 141 | ' doit être le même lors de l\'utilisation du même identifiant de persistance.' |
| 142 | 142 | ); |
| 143 | 143 | } |
@@ -147,38 +147,38 @@ discard block |
||
| 147 | 147 | return true; |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - $servers = []; |
|
| 150 | + $servers = [ ]; |
|
| 151 | 151 | |
| 152 | - foreach ($this->_config['servers'] as $server) { |
|
| 153 | - $servers[] = $this->parseServerString($server); |
|
| 152 | + foreach ($this->_config[ 'servers' ] as $server) { |
|
| 153 | + $servers[ ] = $this->parseServerString($server); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | - if (! $this->_Memcached->addServers($servers)) { |
|
| 156 | + if (!$this->_Memcached->addServers($servers)) { |
|
| 157 | 157 | return false; |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | - if (is_array($this->_config['options'])) { |
|
| 161 | - foreach ($this->_config['options'] as $opt => $value) { |
|
| 160 | + if (is_array($this->_config[ 'options' ])) { |
|
| 161 | + foreach ($this->_config[ 'options' ] as $opt => $value) { |
|
| 162 | 162 | $this->_Memcached->setOption($opt, $value); |
| 163 | 163 | } |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | - if (empty($this->_config['username']) && ! empty($this->_config['login'])) { |
|
| 166 | + if (empty($this->_config[ 'username' ]) && !empty($this->_config[ 'login' ])) { |
|
| 167 | 167 | throw new InvalidArgumentException( |
| 168 | 168 | 'Veuillez passer "nom d\'utilisateur" au lieu de "login" pour vous connecter à Memcached' |
| 169 | 169 | ); |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | - if ($this->_config['username'] !== null && $this->_config['password'] !== null) { |
|
| 173 | - if (! method_exists($this->_Memcached, 'setSaslAuthData')) { |
|
| 172 | + if ($this->_config[ 'username' ] !== null && $this->_config[ 'password' ] !== null) { |
|
| 173 | + if (!method_exists($this->_Memcached, 'setSaslAuthData')) { |
|
| 174 | 174 | throw new InvalidArgumentException( |
| 175 | 175 | "L'extension Memcached n'est pas construite avec le support SASL" |
| 176 | 176 | ); |
| 177 | 177 | } |
| 178 | 178 | $this->_Memcached->setOption(BaseMemcached::OPT_BINARY_PROTOCOL, true); |
| 179 | 179 | $this->_Memcached->setSaslAuthData( |
| 180 | - $this->_config['username'], |
|
| 181 | - $this->_config['password'] |
|
| 180 | + $this->_config[ 'username' ], |
|
| 181 | + $this->_config[ 'password' ] |
|
| 182 | 182 | ); |
| 183 | 183 | } |
| 184 | 184 | |
@@ -194,8 +194,8 @@ discard block |
||
| 194 | 194 | { |
| 195 | 195 | $this->_Memcached->setOption(BaseMemcached::OPT_LIBKETAMA_COMPATIBLE, true); |
| 196 | 196 | |
| 197 | - $serializer = strtolower($this->_config['serialize']); |
|
| 198 | - if (! isset($this->_serializers[$serializer])) { |
|
| 197 | + $serializer = strtolower($this->_config[ 'serialize' ]); |
|
| 198 | + if (!isset($this->_serializers[ $serializer ])) { |
|
| 199 | 199 | throw new InvalidArgumentException( |
| 200 | 200 | sprintf('%s n\'est pas un moteur de sérialisation valide pour Memcached', $serializer) |
| 201 | 201 | ); |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | |
| 204 | 204 | if ( |
| 205 | 205 | $serializer !== 'php' |
| 206 | - && ! constant('Memcached::HAVE_' . strtoupper($serializer)) |
|
| 206 | + && !constant('Memcached::HAVE_'.strtoupper($serializer)) |
|
| 207 | 207 | ) { |
| 208 | 208 | throw new InvalidArgumentException( |
| 209 | 209 | sprintf('L\'extension Memcached n\'est pas compilée avec la prise en charge de %s', $serializer) |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | |
| 213 | 213 | $this->_Memcached->setOption( |
| 214 | 214 | BaseMemcached::OPT_SERIALIZER, |
| 215 | - $this->_serializers[$serializer] |
|
| 215 | + $this->_serializers[ $serializer ] |
|
| 216 | 216 | ); |
| 217 | 217 | |
| 218 | 218 | // Check for Amazon ElastiCache instance |
@@ -228,7 +228,7 @@ discard block |
||
| 228 | 228 | |
| 229 | 229 | $this->_Memcached->setOption( |
| 230 | 230 | BaseMemcached::OPT_COMPRESSION, |
| 231 | - (bool) $this->_config['compress'] |
|
| 231 | + (bool) $this->_config[ 'compress' ] |
|
| 232 | 232 | ); |
| 233 | 233 | } |
| 234 | 234 | |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | { |
| 244 | 244 | $socketTransport = 'unix://'; |
| 245 | 245 | if (str_starts_with($server, $socketTransport)) { |
| 246 | - return [substr($server, strlen($socketTransport)), 0]; |
|
| 246 | + return [ substr($server, strlen($socketTransport)), 0 ]; |
|
| 247 | 247 | } |
| 248 | 248 | if (substr($server, 0, 1) === '[') { |
| 249 | 249 | $position = strpos($server, ']:'); |
@@ -260,7 +260,7 @@ discard block |
||
| 260 | 260 | $port = substr($server, $position + 1); |
| 261 | 261 | } |
| 262 | 262 | |
| 263 | - return [$host, (int) $port]; |
|
| 263 | + return [ $host, (int) $port ]; |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | /** |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | * |
| 281 | 281 | * @see https://www.php.net/manual/en/memcached.set.php |
| 282 | 282 | */ |
| 283 | - public function set(string $key, mixed $value, DateInterval|int|null $ttl = null): bool |
|
| 283 | + public function set(string $key, mixed $value, DateInterval | int | null $ttl = null): bool |
|
| 284 | 284 | { |
| 285 | 285 | $duration = $this->duration($ttl); |
| 286 | 286 | |
@@ -290,12 +290,12 @@ discard block |
||
| 290 | 290 | /** |
| 291 | 291 | * {@inheritDoc} |
| 292 | 292 | */ |
| 293 | - public function setMultiple(iterable $values, DateInterval|int|null $ttl = null): bool |
|
| 293 | + public function setMultiple(iterable $values, DateInterval | int | null $ttl = null): bool |
|
| 294 | 294 | { |
| 295 | - $cacheData = []; |
|
| 295 | + $cacheData = [ ]; |
|
| 296 | 296 | |
| 297 | 297 | foreach ($values as $key => $value) { |
| 298 | - $cacheData[$this->_key($key)] = $value; |
|
| 298 | + $cacheData[ $this->_key($key) ] = $value; |
|
| 299 | 299 | } |
| 300 | 300 | $duration = $this->duration($ttl); |
| 301 | 301 | |
@@ -323,10 +323,10 @@ discard block |
||
| 323 | 323 | */ |
| 324 | 324 | public function getMultiple(iterable $keys, mixed $default = null): iterable |
| 325 | 325 | { |
| 326 | - $cacheKeys = []; |
|
| 326 | + $cacheKeys = [ ]; |
|
| 327 | 327 | |
| 328 | 328 | foreach ($keys as $key) { |
| 329 | - $cacheKeys[$key] = $this->_key($key); |
|
| 329 | + $cacheKeys[ $key ] = $this->_key($key); |
|
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | $values = $this->_Memcached->getMulti($cacheKeys); |
@@ -334,9 +334,9 @@ discard block |
||
| 334 | 334 | return array_fill_keys(array_keys($cacheKeys), $default); |
| 335 | 335 | } |
| 336 | 336 | |
| 337 | - $return = []; |
|
| 337 | + $return = [ ]; |
|
| 338 | 338 | foreach ($cacheKeys as $original => $prefixed) { |
| 339 | - $return[$original] = $values[$prefixed] ?? $default; |
|
| 339 | + $return[ $original ] = $values[ $prefixed ] ?? $default; |
|
| 340 | 340 | } |
| 341 | 341 | |
| 342 | 342 | return $return; |
@@ -371,10 +371,10 @@ discard block |
||
| 371 | 371 | */ |
| 372 | 372 | public function deleteMultiple(iterable $keys): bool |
| 373 | 373 | { |
| 374 | - $cacheKeys = []; |
|
| 374 | + $cacheKeys = [ ]; |
|
| 375 | 375 | |
| 376 | 376 | foreach ($keys as $key) { |
| 377 | - $cacheKeys[] = $this->_key($key); |
|
| 377 | + $cacheKeys[ ] = $this->_key($key); |
|
| 378 | 378 | } |
| 379 | 379 | |
| 380 | 380 | return (bool) $this->_Memcached->deleteMulti($cacheKeys); |
@@ -391,7 +391,7 @@ discard block |
||
| 391 | 391 | } |
| 392 | 392 | |
| 393 | 393 | foreach ($keys as $key) { |
| 394 | - if (str_starts_with($key, $this->_config['prefix'])) { |
|
| 394 | + if (str_starts_with($key, $this->_config[ 'prefix' ])) { |
|
| 395 | 395 | $this->_Memcached->delete($key); |
| 396 | 396 | } |
| 397 | 397 | } |
@@ -404,7 +404,7 @@ discard block |
||
| 404 | 404 | */ |
| 405 | 405 | public function add(string $key, mixed $value): bool |
| 406 | 406 | { |
| 407 | - $duration = $this->_config['duration']; |
|
| 407 | + $duration = $this->_config[ 'duration' ]; |
|
| 408 | 408 | $key = $this->_key($key); |
| 409 | 409 | |
| 410 | 410 | return $this->_Memcached->add($key, $value, $duration); |
@@ -423,28 +423,28 @@ discard block |
||
| 423 | 423 | */ |
| 424 | 424 | public function groups(): array |
| 425 | 425 | { |
| 426 | - if ($this->_compiledGroupNames === []) { |
|
| 427 | - foreach ($this->_config['groups'] as $group) { |
|
| 428 | - $this->_compiledGroupNames[] = $this->_config['prefix'] . $group; |
|
| 426 | + if ($this->_compiledGroupNames === [ ]) { |
|
| 427 | + foreach ($this->_config[ 'groups' ] as $group) { |
|
| 428 | + $this->_compiledGroupNames[ ] = $this->_config[ 'prefix' ].$group; |
|
| 429 | 429 | } |
| 430 | 430 | } |
| 431 | 431 | |
| 432 | - $groups = $this->_Memcached->getMulti($this->_compiledGroupNames) ?: []; |
|
| 433 | - if (count($groups) !== count($this->_config['groups'])) { |
|
| 432 | + $groups = $this->_Memcached->getMulti($this->_compiledGroupNames) ?: [ ]; |
|
| 433 | + if (count($groups) !== count($this->_config[ 'groups' ])) { |
|
| 434 | 434 | foreach ($this->_compiledGroupNames as $group) { |
| 435 | - if (! isset($groups[$group])) { |
|
| 435 | + if (!isset($groups[ $group ])) { |
|
| 436 | 436 | $this->_Memcached->set($group, 1, 0); |
| 437 | - $groups[$group] = 1; |
|
| 437 | + $groups[ $group ] = 1; |
|
| 438 | 438 | } |
| 439 | 439 | } |
| 440 | 440 | ksort($groups); |
| 441 | 441 | } |
| 442 | 442 | |
| 443 | - $result = []; |
|
| 443 | + $result = [ ]; |
|
| 444 | 444 | $groups = array_values($groups); |
| 445 | 445 | |
| 446 | - foreach ($this->_config['groups'] as $i => $group) { |
|
| 447 | - $result[] = $group . $groups[$i]; |
|
| 446 | + foreach ($this->_config[ 'groups' ] as $i => $group) { |
|
| 447 | + $result[ ] = $group.$groups[ $i ]; |
|
| 448 | 448 | } |
| 449 | 449 | |
| 450 | 450 | return $result; |
@@ -455,6 +455,6 @@ discard block |
||
| 455 | 455 | */ |
| 456 | 456 | public function clearGroup(string $group): bool |
| 457 | 457 | { |
| 458 | - return (bool) $this->_Memcached->increment($this->_config['prefix'] . $group); |
|
| 458 | + return (bool) $this->_Memcached->increment($this->_config[ 'prefix' ].$group); |
|
| 459 | 459 | } |
| 460 | 460 | } |
@@ -57,18 +57,18 @@ discard block |
||
| 57 | 57 | { |
| 58 | 58 | $uri = $request->getUri(); |
| 59 | 59 | |
| 60 | - $query = ''; |
|
| 61 | - if ($this->cacheQueryString !== false) { |
|
| 62 | - parse_str($uri->getQuery(), $queryParams); |
|
| 63 | - |
|
| 64 | - if (is_array($this->cacheQueryString)) { |
|
| 65 | - // Filtrer seulement les paramètres spécifiés |
|
| 66 | - $queryParams = array_intersect_key($queryParams, array_flip($this->cacheQueryString)); |
|
| 67 | - } |
|
| 68 | - // Trier pour garantir l'ordre et éviter les doublons avec paramètres dans un ordre différent |
|
| 69 | - ksort($queryParams); |
|
| 70 | - $query = http_build_query($queryParams); |
|
| 71 | - } |
|
| 60 | + $query = ''; |
|
| 61 | + if ($this->cacheQueryString !== false) { |
|
| 62 | + parse_str($uri->getQuery(), $queryParams); |
|
| 63 | + |
|
| 64 | + if (is_array($this->cacheQueryString)) { |
|
| 65 | + // Filtrer seulement les paramètres spécifiés |
|
| 66 | + $queryParams = array_intersect_key($queryParams, array_flip($this->cacheQueryString)); |
|
| 67 | + } |
|
| 68 | + // Trier pour garantir l'ordre et éviter les doublons avec paramètres dans un ordre différent |
|
| 69 | + ksort($queryParams); |
|
| 70 | + $query = http_build_query($queryParams); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | 73 | return md5($uri->withFragment('')->withQuery($query)); |
| 74 | 74 | } |
@@ -102,19 +102,19 @@ discard block |
||
| 102 | 102 | { |
| 103 | 103 | if ($cachedResponse = $this->cache->get($this->generateCacheKey($request))) { |
| 104 | 104 | if (!is_string($cachedResponse)) { |
| 105 | - throw new Exception('Données de cache corrompues'); |
|
| 106 | - } |
|
| 105 | + throw new Exception('Données de cache corrompues'); |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - $cachedResponse = unserialize($cachedResponse, ['allowed_classes' => false]); |
|
| 108 | + $cachedResponse = unserialize($cachedResponse, ['allowed_classes' => false]); |
|
| 109 | 109 | |
| 110 | - if (!is_array($cachedResponse) || !isset($cachedResponse['output'], $cachedResponse['headers'])) { |
|
| 111 | - throw new Exception('Structure de cache invalide'); |
|
| 112 | - } |
|
| 110 | + if (!is_array($cachedResponse) || !isset($cachedResponse['output'], $cachedResponse['headers'])) { |
|
| 111 | + throw new Exception('Structure de cache invalide'); |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - // Validation des headers |
|
| 115 | - if (!is_array($cachedResponse['headers'])) { |
|
| 116 | - throw new Exception('Headers de cache invalides'); |
|
| 117 | - } |
|
| 114 | + // Validation des headers |
|
| 115 | + if (!is_array($cachedResponse['headers'])) { |
|
| 116 | + throw new Exception('Headers de cache invalides'); |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | 119 | $headers = $cachedResponse['headers']; |
| 120 | 120 | $output = $cachedResponse['output']; |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * Veuillez noter que cela peut entraîner de nombreux fichiers de cache générés encore et encore pour la même page. |
| 38 | 38 | * array('q') = Activé, mais ne prend en compte que la liste spécifiée de paramètres de requête. |
| 39 | 39 | */ |
| 40 | - public function __construct(private CacheInterface $cache, private array|bool $cacheQueryString = false) |
|
| 40 | + public function __construct(private CacheInterface $cache, private array | bool $cacheQueryString = false) |
|
| 41 | 41 | { |
| 42 | 42 | } |
| 43 | 43 | |
@@ -82,15 +82,15 @@ discard block |
||
| 82 | 82 | return true; |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - $headers = []; |
|
| 85 | + $headers = [ ]; |
|
| 86 | 86 | |
| 87 | 87 | foreach (array_keys($response->getHeaders()) as $header) { |
| 88 | - $headers[$header] = $response->getHeaderLine($header); |
|
| 88 | + $headers[ $header ] = $response->getHeaderLine($header); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | return $this->cache->set( |
| 92 | 92 | $this->generateCacheKey($request), |
| 93 | - serialize(['headers' => $headers, 'output' => $response->getBody()->getContents()]), |
|
| 93 | + serialize([ 'headers' => $headers, 'output' => $response->getBody()->getContents() ]), |
|
| 94 | 94 | $this->ttl |
| 95 | 95 | ); |
| 96 | 96 | } |
@@ -105,19 +105,19 @@ discard block |
||
| 105 | 105 | throw new Exception('Données de cache corrompues'); |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - $cachedResponse = unserialize($cachedResponse, ['allowed_classes' => false]); |
|
| 108 | + $cachedResponse = unserialize($cachedResponse, [ 'allowed_classes' => false ]); |
|
| 109 | 109 | |
| 110 | - if (!is_array($cachedResponse) || !isset($cachedResponse['output'], $cachedResponse['headers'])) { |
|
| 110 | + if (!is_array($cachedResponse) || !isset($cachedResponse[ 'output' ], $cachedResponse[ 'headers' ])) { |
|
| 111 | 111 | throw new Exception('Structure de cache invalide'); |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | // Validation des headers |
| 115 | - if (!is_array($cachedResponse['headers'])) { |
|
| 115 | + if (!is_array($cachedResponse[ 'headers' ])) { |
|
| 116 | 116 | throw new Exception('Headers de cache invalides'); |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - $headers = $cachedResponse['headers']; |
|
| 120 | - $output = $cachedResponse['output']; |
|
| 119 | + $headers = $cachedResponse[ 'headers' ]; |
|
| 120 | + $output = $cachedResponse[ 'output' ]; |
|
| 121 | 121 | |
| 122 | 122 | // Effacer tous les en-têtes par défaut |
| 123 | 123 | foreach (array_keys($response->getHeaders()) as $key) { |