@@ -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, |
@@ -61,14 +61,14 @@ discard block |
||
| 61 | 61 | /** |
| 62 | 62 | * {@inheritDoc} |
| 63 | 63 | */ |
| 64 | - public function init(array $config = []): bool |
|
| 64 | + public function init(array $config = [ ]): bool |
|
| 65 | 65 | { |
| 66 | - if (! extension_loaded('redis')) { |
|
| 66 | + if (!extension_loaded('redis')) { |
|
| 67 | 67 | throw new RuntimeException('L\'extension `redis` doit être activée pour utiliser RedisHandler.'); |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - if (! empty($config['host'])) { |
|
| 71 | - $config['server'] = $config['host']; |
|
| 70 | + if (!empty($config[ 'host' ])) { |
|
| 71 | + $config[ 'server' ] = $config[ 'host' ]; |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | parent::init($config); |
@@ -85,20 +85,20 @@ discard block |
||
| 85 | 85 | { |
| 86 | 86 | try { |
| 87 | 87 | $this->_Redis = new Redis(); |
| 88 | - if (! empty($this->_config['unix_socket'])) { |
|
| 89 | - $return = $this->_Redis->connect($this->_config['unix_socket']); |
|
| 90 | - } elseif (empty($this->_config['persistent'])) { |
|
| 88 | + if (!empty($this->_config[ 'unix_socket' ])) { |
|
| 89 | + $return = $this->_Redis->connect($this->_config[ 'unix_socket' ]); |
|
| 90 | + } elseif (empty($this->_config[ 'persistent' ])) { |
|
| 91 | 91 | $return = $this->_Redis->connect( |
| 92 | - $this->_config['server'], |
|
| 93 | - (int) $this->_config['port'], |
|
| 94 | - (int) $this->_config['timeout'] |
|
| 92 | + $this->_config[ 'server' ], |
|
| 93 | + (int) $this->_config[ 'port' ], |
|
| 94 | + (int) $this->_config[ 'timeout' ] |
|
| 95 | 95 | ); |
| 96 | 96 | } else { |
| 97 | - $persistentId = $this->_config['port'] . $this->_config['timeout'] . $this->_config['database']; |
|
| 97 | + $persistentId = $this->_config[ 'port' ].$this->_config[ 'timeout' ].$this->_config[ 'database' ]; |
|
| 98 | 98 | $return = $this->_Redis->pconnect( |
| 99 | - $this->_config['server'], |
|
| 100 | - (int) $this->_config['port'], |
|
| 101 | - (int) $this->_config['timeout'], |
|
| 99 | + $this->_config[ 'server' ], |
|
| 100 | + (int) $this->_config[ 'port' ], |
|
| 101 | + (int) $this->_config[ 'timeout' ], |
|
| 102 | 102 | $persistentId |
| 103 | 103 | ); |
| 104 | 104 | } |
@@ -106,17 +106,17 @@ discard block |
||
| 106 | 106 | if (function_exists('logger')) { |
| 107 | 107 | $logger = logger(); |
| 108 | 108 | if (is_object($logger) && method_exists($logger, 'error')) { |
| 109 | - $logger->error('RedisEngine n\'a pas pu se connecter. Erreur: ' . $e->getMessage()); |
|
| 109 | + $logger->error('RedisEngine n\'a pas pu se connecter. Erreur: '.$e->getMessage()); |
|
| 110 | 110 | } |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | return false; |
| 114 | 114 | } |
| 115 | - if ($return && $this->_config['password']) { |
|
| 116 | - $return = $this->_Redis->auth($this->_config['password']); |
|
| 115 | + if ($return && $this->_config[ 'password' ]) { |
|
| 116 | + $return = $this->_Redis->auth($this->_config[ 'password' ]); |
|
| 117 | 117 | } |
| 118 | 118 | if ($return) { |
| 119 | - $return = $this->_Redis->select((int) $this->_config['database']); |
|
| 119 | + $return = $this->_Redis->select((int) $this->_config[ 'database' ]); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | return $return; |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | /** |
| 126 | 126 | * {@inheritDoc} |
| 127 | 127 | */ |
| 128 | - public function set(string $key, mixed $value, DateInterval|int|null $ttl = null): bool |
|
| 128 | + public function set(string $key, mixed $value, DateInterval | int | null $ttl = null): bool |
|
| 129 | 129 | { |
| 130 | 130 | $key = $this->_key($key); |
| 131 | 131 | $value = $this->serialize($value); |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | */ |
| 157 | 157 | public function increment(string $key, int $offset = 1) |
| 158 | 158 | { |
| 159 | - $duration = $this->_config['duration']; |
|
| 159 | + $duration = $this->_config[ 'duration' ]; |
|
| 160 | 160 | $key = $this->_key($key); |
| 161 | 161 | |
| 162 | 162 | $value = $this->_Redis->incrBy($key, $offset); |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | */ |
| 173 | 173 | public function decrement(string $key, int $offset = 1) |
| 174 | 174 | { |
| 175 | - $duration = $this->_config['duration']; |
|
| 175 | + $duration = $this->_config[ 'duration' ]; |
|
| 176 | 176 | $key = $this->_key($key); |
| 177 | 177 | |
| 178 | 178 | $value = $this->_Redis->decrBy($key, $offset); |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | |
| 203 | 203 | $isAllDeleted = true; |
| 204 | 204 | $iterator = null; |
| 205 | - $pattern = $this->_config['prefix'] . '*'; |
|
| 205 | + $pattern = $this->_config[ 'prefix' ].'*'; |
|
| 206 | 206 | |
| 207 | 207 | while (true) { |
| 208 | 208 | $keys = $this->_Redis->scan($iterator, $pattern); |
@@ -227,11 +227,11 @@ discard block |
||
| 227 | 227 | */ |
| 228 | 228 | public function add(string $key, mixed $value): bool |
| 229 | 229 | { |
| 230 | - $duration = $this->_config['duration']; |
|
| 230 | + $duration = $this->_config[ 'duration' ]; |
|
| 231 | 231 | $key = $this->_key($key); |
| 232 | 232 | $value = $this->serialize($value); |
| 233 | 233 | |
| 234 | - return (bool) ($this->_Redis->set($key, $value, ['nx', 'ex' => $duration])); |
|
| 234 | + return (bool) ($this->_Redis->set($key, $value, [ 'nx', 'ex' => $duration ])); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /** |
@@ -239,15 +239,15 @@ discard block |
||
| 239 | 239 | */ |
| 240 | 240 | public function groups(): array |
| 241 | 241 | { |
| 242 | - $result = []; |
|
| 242 | + $result = [ ]; |
|
| 243 | 243 | |
| 244 | - foreach ($this->_config['groups'] as $group) { |
|
| 245 | - $value = $this->_Redis->get($this->_config['prefix'] . $group); |
|
| 246 | - if (! $value) { |
|
| 244 | + foreach ($this->_config[ 'groups' ] as $group) { |
|
| 245 | + $value = $this->_Redis->get($this->_config[ 'prefix' ].$group); |
|
| 246 | + if (!$value) { |
|
| 247 | 247 | $value = $this->serialize(1); |
| 248 | - $this->_Redis->set($this->_config['prefix'] . $group, $value); |
|
| 248 | + $this->_Redis->set($this->_config[ 'prefix' ].$group, $value); |
|
| 249 | 249 | } |
| 250 | - $result[] = $group . $value; |
|
| 250 | + $result[ ] = $group.$value; |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | return $result; |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | */ |
| 259 | 259 | public function clearGroup(string $group): bool |
| 260 | 260 | { |
| 261 | - return (bool) $this->_Redis->incr($this->_config['prefix'] . $group); |
|
| 261 | + return (bool) $this->_Redis->incr($this->_config[ 'prefix' ].$group); |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | /** |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | */ |
| 296 | 296 | public function __destruct() |
| 297 | 297 | { |
| 298 | - if (empty($this->_config['persistent']) && $this->_Redis instanceof Redis) { |
|
| 298 | + if (empty($this->_config[ 'persistent' ]) && $this->_Redis instanceof Redis) { |
|
| 299 | 299 | $this->_Redis->close(); |
| 300 | 300 | } |
| 301 | 301 | } |
@@ -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' => 0664, |
| 54 | 54 | 'path' => null, |
@@ -64,15 +64,15 @@ discard block |
||
| 64 | 64 | /** |
| 65 | 65 | * {@inheritDoc} |
| 66 | 66 | */ |
| 67 | - public function init(array $config = []): bool |
|
| 67 | + public function init(array $config = [ ]): bool |
|
| 68 | 68 | { |
| 69 | 69 | parent::init($config); |
| 70 | 70 | |
| 71 | - if ($this->_config['path'] === null) { |
|
| 72 | - $this->_config['path'] = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'blitz-php' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR; |
|
| 71 | + if ($this->_config[ 'path' ] === null) { |
|
| 72 | + $this->_config[ 'path' ] = sys_get_temp_dir().DIRECTORY_SEPARATOR.'blitz-php'.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR; |
|
| 73 | 73 | } |
| 74 | - if (substr($this->_config['path'], -1) !== DIRECTORY_SEPARATOR) { |
|
| 75 | - $this->_config['path'] .= DIRECTORY_SEPARATOR; |
|
| 74 | + if (substr($this->_config[ 'path' ], -1) !== DIRECTORY_SEPARATOR) { |
|
| 75 | + $this->_config[ 'path' ] .= DIRECTORY_SEPARATOR; |
|
| 76 | 76 | } |
| 77 | 77 | if ($this->_groupPrefix) { |
| 78 | 78 | $this->_groupPrefix = str_replace('_', DIRECTORY_SEPARATOR, $this->_groupPrefix); |
@@ -84,9 +84,9 @@ discard block |
||
| 84 | 84 | /** |
| 85 | 85 | * {@inheritDoc} |
| 86 | 86 | */ |
| 87 | - public function set(string $key, mixed $value, DateInterval|int|null $ttl = null): bool |
|
| 87 | + public function set(string $key, mixed $value, DateInterval | int | null $ttl = null): bool |
|
| 88 | 88 | { |
| 89 | - if ($value === '' || ! $this->_init) { |
|
| 89 | + if ($value === '' || !$this->_init) { |
|
| 90 | 90 | return false; |
| 91 | 91 | } |
| 92 | 92 | |
@@ -96,14 +96,14 @@ discard block |
||
| 96 | 96 | return false; |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - if (! empty($this->_config['serialize'])) { |
|
| 99 | + if (!empty($this->_config[ 'serialize' ])) { |
|
| 100 | 100 | $value = serialize($value); |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | $expires = time() + $this->duration($ttl); |
| 104 | - $contents = implode('', [$expires, PHP_EOL, $value, PHP_EOL]); |
|
| 104 | + $contents = implode('', [ $expires, PHP_EOL, $value, PHP_EOL ]); |
|
| 105 | 105 | |
| 106 | - if ($this->_config['lock']) { |
|
| 106 | + if ($this->_config[ 'lock' ]) { |
|
| 107 | 107 | /** @psalm-suppress PossiblyNullReference */ |
| 108 | 108 | $this->_File->flock(LOCK_EX); |
| 109 | 109 | } |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | && $this->_File->fwrite($contents) |
| 115 | 115 | && $this->_File->fflush(); |
| 116 | 116 | |
| 117 | - if ($this->_config['lock']) { |
|
| 117 | + if ($this->_config[ 'lock' ]) { |
|
| 118 | 118 | $this->_File->flock(LOCK_UN); |
| 119 | 119 | } |
| 120 | 120 | $this->_File = null; |
@@ -129,11 +129,11 @@ discard block |
||
| 129 | 129 | { |
| 130 | 130 | $key = $this->_key($key); |
| 131 | 131 | |
| 132 | - if (! $this->_init || $this->_setKey($key) === false) { |
|
| 132 | + if (!$this->_init || $this->_setKey($key) === false) { |
|
| 133 | 133 | return $default; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - if ($this->_config['lock']) { |
|
| 136 | + if ($this->_config[ 'lock' ]) { |
|
| 137 | 137 | /** @psalm-suppress PossiblyNullReference */ |
| 138 | 138 | $this->_File->flock(LOCK_SH); |
| 139 | 139 | } |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | $cachetime = (int) $this->_File->current(); |
| 145 | 145 | |
| 146 | 146 | if ($cachetime < $time) { |
| 147 | - if ($this->_config['lock']) { |
|
| 147 | + if ($this->_config[ 'lock' ]) { |
|
| 148 | 148 | $this->_File->flock(LOCK_UN); |
| 149 | 149 | } |
| 150 | 150 | |
@@ -160,13 +160,13 @@ discard block |
||
| 160 | 160 | $this->_File->next(); |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | - if ($this->_config['lock']) { |
|
| 163 | + if ($this->_config[ 'lock' ]) { |
|
| 164 | 164 | $this->_File->flock(LOCK_UN); |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | $data = trim($data); |
| 168 | 168 | |
| 169 | - if ($data !== '' && ! empty($this->_config['serialize'])) { |
|
| 169 | + if ($data !== '' && !empty($this->_config[ 'serialize' ])) { |
|
| 170 | 170 | $data = unserialize($data); |
| 171 | 171 | } |
| 172 | 172 | |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | { |
| 181 | 181 | $key = $this->_key($key); |
| 182 | 182 | |
| 183 | - if ($this->_setKey($key) === false || ! $this->_init) { |
|
| 183 | + if ($this->_setKey($key) === false || !$this->_init) { |
|
| 184 | 184 | return false; |
| 185 | 185 | } |
| 186 | 186 | |
@@ -202,22 +202,22 @@ discard block |
||
| 202 | 202 | */ |
| 203 | 203 | public function clear(): bool |
| 204 | 204 | { |
| 205 | - if (! $this->_init) { |
|
| 205 | + if (!$this->_init) { |
|
| 206 | 206 | return false; |
| 207 | 207 | } |
| 208 | 208 | $this->_File = null; |
| 209 | 209 | |
| 210 | - $this->_clearDirectory($this->_config['path']); |
|
| 210 | + $this->_clearDirectory($this->_config[ 'path' ]); |
|
| 211 | 211 | |
| 212 | 212 | $directory = new RecursiveDirectoryIterator( |
| 213 | - $this->_config['path'], |
|
| 213 | + $this->_config[ 'path' ], |
|
| 214 | 214 | FilesystemIterator::SKIP_DOTS |
| 215 | 215 | ); |
| 216 | 216 | $contents = new RecursiveIteratorIterator( |
| 217 | 217 | $directory, |
| 218 | 218 | RecursiveIteratorIterator::SELF_FIRST |
| 219 | 219 | ); |
| 220 | - $cleared = []; |
|
| 220 | + $cleared = [ ]; |
|
| 221 | 221 | /** @var SplFileInfo $fileInfo */ |
| 222 | 222 | foreach ($contents as $fileInfo) { |
| 223 | 223 | if ($fileInfo->isFile()) { |
@@ -227,16 +227,16 @@ discard block |
||
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | $realPath = $fileInfo->getRealPath(); |
| 230 | - if (! $realPath) { |
|
| 230 | + if (!$realPath) { |
|
| 231 | 231 | unset($fileInfo); |
| 232 | 232 | |
| 233 | 233 | continue; |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | - $path = $realPath . DIRECTORY_SEPARATOR; |
|
| 237 | - if (! in_array($path, $cleared, true)) { |
|
| 236 | + $path = $realPath.DIRECTORY_SEPARATOR; |
|
| 237 | + if (!in_array($path, $cleared, true)) { |
|
| 238 | 238 | $this->_clearDirectory($path); |
| 239 | - $cleared[] = $path; |
|
| 239 | + $cleared[ ] = $path; |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | // les itérateurs internes possibles doivent également être désactivés pour que les verrous sur les parents soient libérés |
@@ -255,24 +255,24 @@ discard block |
||
| 255 | 255 | */ |
| 256 | 256 | protected function _clearDirectory(string $path): void |
| 257 | 257 | { |
| 258 | - if (! is_dir($path)) { |
|
| 258 | + if (!is_dir($path)) { |
|
| 259 | 259 | return; |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | $dir = dir($path); |
| 263 | - if (! $dir) { |
|
| 263 | + if (!$dir) { |
|
| 264 | 264 | return; |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | - $prefixLength = strlen($this->_config['prefix']); |
|
| 267 | + $prefixLength = strlen($this->_config[ 'prefix' ]); |
|
| 268 | 268 | |
| 269 | 269 | while (($entry = $dir->read()) !== false) { |
| 270 | - if (substr($entry, 0, $prefixLength) !== $this->_config['prefix']) { |
|
| 270 | + if (substr($entry, 0, $prefixLength) !== $this->_config[ 'prefix' ]) { |
|
| 271 | 271 | continue; |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | try { |
| 275 | - $file = new SplFileObject($path . $entry, 'r'); |
|
| 275 | + $file = new SplFileObject($path.$entry, 'r'); |
|
| 276 | 276 | } catch (Exception $e) { |
| 277 | 277 | continue; |
| 278 | 278 | } |
@@ -315,7 +315,7 @@ discard block |
||
| 315 | 315 | */ |
| 316 | 316 | public function info() |
| 317 | 317 | { |
| 318 | - return $this->getDirFileInfo($this->_config['path']); |
|
| 318 | + return $this->getDirFileInfo($this->_config[ 'path' ]); |
|
| 319 | 319 | } |
| 320 | 320 | |
| 321 | 321 | /** |
@@ -332,15 +332,15 @@ discard block |
||
| 332 | 332 | if ($this->_groupPrefix) { |
| 333 | 333 | $groups = vsprintf($this->_groupPrefix, $this->groups()); |
| 334 | 334 | } |
| 335 | - $dir = $this->_config['path'] . $groups; |
|
| 335 | + $dir = $this->_config[ 'path' ].$groups; |
|
| 336 | 336 | |
| 337 | - if (! is_dir($dir)) { |
|
| 337 | + if (!is_dir($dir)) { |
|
| 338 | 338 | mkdir($dir, 0775, true); |
| 339 | 339 | } |
| 340 | 340 | |
| 341 | - $path = new SplFileInfo($dir . $key); |
|
| 341 | + $path = new SplFileInfo($dir.$key); |
|
| 342 | 342 | |
| 343 | - if (! $createKey && ! $path->isFile()) { |
|
| 343 | + if (!$createKey && !$path->isFile()) { |
|
| 344 | 344 | return false; |
| 345 | 345 | } |
| 346 | 346 | if ( |
@@ -359,11 +359,11 @@ discard block |
||
| 359 | 359 | } |
| 360 | 360 | unset($path); |
| 361 | 361 | |
| 362 | - if (! $exists && ! chmod($this->_File->getPathname(), (int) $this->_config['mask'])) { |
|
| 362 | + if (!$exists && !chmod($this->_File->getPathname(), (int) $this->_config[ 'mask' ])) { |
|
| 363 | 363 | trigger_error(sprintf( |
| 364 | 364 | 'Impossible d\'appliquer le masque d\'autorisation "%s" sur le fichier cache "%s"', |
| 365 | 365 | $this->_File->getPathname(), |
| 366 | - $this->_config['mask'] |
|
| 366 | + $this->_config[ 'mask' ] |
|
| 367 | 367 | ), E_USER_WARNING); |
| 368 | 368 | } |
| 369 | 369 | } |
@@ -376,21 +376,21 @@ discard block |
||
| 376 | 376 | */ |
| 377 | 377 | protected function _active(): bool |
| 378 | 378 | { |
| 379 | - $dir = new SplFileInfo($this->_config['path']); |
|
| 379 | + $dir = new SplFileInfo($this->_config[ 'path' ]); |
|
| 380 | 380 | $path = $dir->getPathname(); |
| 381 | 381 | $success = true; |
| 382 | - if (! is_dir($path)) { |
|
| 382 | + if (!is_dir($path)) { |
|
| 383 | 383 | // phpcs:disable |
| 384 | 384 | $success = @mkdir($path, 0775, true); |
| 385 | 385 | // phpcs:enable |
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | $isWritableDir = ($dir->isDir() && $dir->isWritable()); |
| 389 | - if (! $success || ($this->_init && ! $isWritableDir)) { |
|
| 389 | + if (!$success || ($this->_init && !$isWritableDir)) { |
|
| 390 | 390 | $this->_init = false; |
| 391 | 391 | trigger_error(sprintf( |
| 392 | 392 | '%s is not writable', |
| 393 | - $this->_config['path'] |
|
| 393 | + $this->_config[ 'path' ] |
|
| 394 | 394 | ), E_USER_WARNING); |
| 395 | 395 | } |
| 396 | 396 | |
@@ -406,7 +406,7 @@ discard block |
||
| 406 | 406 | |
| 407 | 407 | if (preg_match('/[\/\\<>?:|*"]/', $key)) { |
| 408 | 408 | throw new InvalidArgumentException( |
| 409 | - "La clé de cache `{$key}` contient des caractères non valides. " . |
|
| 409 | + "La clé de cache `{$key}` contient des caractères non valides. ". |
|
| 410 | 410 | 'Vous ne pouvez pas utiliser /, \\, <, >, ?, :, |, * ou " dans les clés de cache.' |
| 411 | 411 | ); |
| 412 | 412 | } |
@@ -421,17 +421,17 @@ discard block |
||
| 421 | 421 | { |
| 422 | 422 | $this->_File = null; |
| 423 | 423 | |
| 424 | - $prefix = (string) $this->_config['prefix']; |
|
| 424 | + $prefix = (string) $this->_config[ 'prefix' ]; |
|
| 425 | 425 | |
| 426 | - $directoryIterator = new RecursiveDirectoryIterator($this->_config['path']); |
|
| 426 | + $directoryIterator = new RecursiveDirectoryIterator($this->_config[ 'path' ]); |
|
| 427 | 427 | $contents = new RecursiveIteratorIterator( |
| 428 | 428 | $directoryIterator, |
| 429 | 429 | RecursiveIteratorIterator::CHILD_FIRST |
| 430 | 430 | ); |
| 431 | 431 | $filtered = new CallbackFilterIterator( |
| 432 | 432 | $contents, |
| 433 | - static function (SplFileInfo $current) use ($group, $prefix) { |
|
| 434 | - if (! $current->isFile()) { |
|
| 433 | + static function(SplFileInfo $current) use ($group, $prefix) { |
|
| 434 | + if (!$current->isFile()) { |
|
| 435 | 435 | return false; |
| 436 | 436 | } |
| 437 | 437 | |
@@ -443,7 +443,7 @@ discard block |
||
| 443 | 443 | |
| 444 | 444 | $pos = strpos( |
| 445 | 445 | $current->getPathname(), |
| 446 | - DIRECTORY_SEPARATOR . $group . DIRECTORY_SEPARATOR |
|
| 446 | + DIRECTORY_SEPARATOR.$group.DIRECTORY_SEPARATOR |
|
| 447 | 447 | ); |
| 448 | 448 | |
| 449 | 449 | return $pos !== false; |
@@ -478,23 +478,23 @@ discard block |
||
| 478 | 478 | */ |
| 479 | 479 | protected function getDirFileInfo(string $sourceDir, bool $topLevelOnly = true, bool $_recursion = false) |
| 480 | 480 | { |
| 481 | - static $_filedata = []; |
|
| 481 | + static $_filedata = [ ]; |
|
| 482 | 482 | $relativePath = $sourceDir; |
| 483 | 483 | |
| 484 | 484 | if ($fp = @opendir($sourceDir)) { |
| 485 | 485 | // réinitialise le tableau et s'assure que $source_dir a une barre oblique à la fin de l'appel initial |
| 486 | 486 | if ($_recursion === false) { |
| 487 | - $_filedata = []; |
|
| 488 | - $sourceDir = rtrim(realpath($sourceDir) ?: $sourceDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; |
|
| 487 | + $_filedata = [ ]; |
|
| 488 | + $sourceDir = rtrim(realpath($sourceDir) ?: $sourceDir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; |
|
| 489 | 489 | } |
| 490 | 490 | |
| 491 | 491 | // Utilisé pour être foreach (scandir($source_dir, 1) comme $file), mais scandir() n'est tout simplement pas aussi rapide |
| 492 | 492 | while (false !== ($file = readdir($fp))) { |
| 493 | - if (is_dir($sourceDir . $file) && $file[0] !== '.' && $topLevelOnly === false) { |
|
| 494 | - $this->getDirFileInfo($sourceDir . $file . DIRECTORY_SEPARATOR, $topLevelOnly, true); |
|
| 495 | - } elseif (! is_dir($sourceDir . $file) && $file[0] !== '.') { |
|
| 496 | - $_filedata[$file] = $this->getFileInfo($sourceDir . $file); |
|
| 497 | - $_filedata[$file]['relative_path'] = $relativePath; |
|
| 493 | + if (is_dir($sourceDir.$file) && $file[ 0 ] !== '.' && $topLevelOnly === false) { |
|
| 494 | + $this->getDirFileInfo($sourceDir.$file.DIRECTORY_SEPARATOR, $topLevelOnly, true); |
|
| 495 | + } elseif (!is_dir($sourceDir.$file) && $file[ 0 ] !== '.') { |
|
| 496 | + $_filedata[ $file ] = $this->getFileInfo($sourceDir.$file); |
|
| 497 | + $_filedata[ $file ][ 'relative_path' ] = $relativePath; |
|
| 498 | 498 | } |
| 499 | 499 | } |
| 500 | 500 | |
@@ -516,9 +516,9 @@ discard block |
||
| 516 | 516 | * |
| 517 | 517 | * @return array|false |
| 518 | 518 | */ |
| 519 | - protected function getFileInfo(string $file, $returnedValues = ['name', 'server_path', 'size', 'date']) |
|
| 519 | + protected function getFileInfo(string $file, $returnedValues = [ 'name', 'server_path', 'size', 'date' ]) |
|
| 520 | 520 | { |
| 521 | - if (! is_file($file)) { |
|
| 521 | + if (!is_file($file)) { |
|
| 522 | 522 | return false; |
| 523 | 523 | } |
| 524 | 524 | |
@@ -526,40 +526,40 @@ discard block |
||
| 526 | 526 | $returnedValues = explode(',', $returnedValues); |
| 527 | 527 | } |
| 528 | 528 | |
| 529 | - $fileInfo = []; |
|
| 529 | + $fileInfo = [ ]; |
|
| 530 | 530 | |
| 531 | 531 | foreach ($returnedValues as $key) { |
| 532 | 532 | switch ($key) { |
| 533 | 533 | case 'name': |
| 534 | - $fileInfo['name'] = basename($file); |
|
| 534 | + $fileInfo[ 'name' ] = basename($file); |
|
| 535 | 535 | break; |
| 536 | 536 | |
| 537 | 537 | case 'server_path': |
| 538 | - $fileInfo['server_path'] = $file; |
|
| 538 | + $fileInfo[ 'server_path' ] = $file; |
|
| 539 | 539 | break; |
| 540 | 540 | |
| 541 | 541 | case 'size': |
| 542 | - $fileInfo['size'] = filesize($file); |
|
| 542 | + $fileInfo[ 'size' ] = filesize($file); |
|
| 543 | 543 | break; |
| 544 | 544 | |
| 545 | 545 | case 'date': |
| 546 | - $fileInfo['date'] = filemtime($file); |
|
| 546 | + $fileInfo[ 'date' ] = filemtime($file); |
|
| 547 | 547 | break; |
| 548 | 548 | |
| 549 | 549 | case 'readable': |
| 550 | - $fileInfo['readable'] = is_readable($file); |
|
| 550 | + $fileInfo[ 'readable' ] = is_readable($file); |
|
| 551 | 551 | break; |
| 552 | 552 | |
| 553 | 553 | case 'writable': |
| 554 | - $fileInfo['writable'] = is_writable($file); |
|
| 554 | + $fileInfo[ 'writable' ] = is_writable($file); |
|
| 555 | 555 | break; |
| 556 | 556 | |
| 557 | 557 | case 'executable': |
| 558 | - $fileInfo['executable'] = is_executable($file); |
|
| 558 | + $fileInfo[ 'executable' ] = is_executable($file); |
|
| 559 | 559 | break; |
| 560 | 560 | |
| 561 | 561 | case 'fileperms': |
| 562 | - $fileInfo['fileperms'] = fileperms($file); |
|
| 562 | + $fileInfo[ 'fileperms' ] = fileperms($file); |
|
| 563 | 563 | break; |
| 564 | 564 | } |
| 565 | 565 | } |