@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | /** |
73 | 73 | * Configuration des caches |
74 | 74 | */ |
75 | - protected array $config = []; |
|
75 | + protected array $config = [ ]; |
|
76 | 76 | |
77 | 77 | /** |
78 | 78 | * Adapter a utiliser pour la mise en cache |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | /** |
83 | 83 | * Constructeur |
84 | 84 | */ |
85 | - public function __construct(array $config = []) |
|
85 | + public function __construct(array $config = [ ]) |
|
86 | 86 | { |
87 | 87 | $this->setConfig($config); |
88 | 88 | } |
@@ -105,51 +105,51 @@ discard block |
||
105 | 105 | */ |
106 | 106 | protected function factory(): CacheInterface |
107 | 107 | { |
108 | - if (! static::$_enabled) { |
|
108 | + if (!static::$_enabled) { |
|
109 | 109 | return new Dummy(); |
110 | 110 | } |
111 | - if (! empty($this->adapter)) { |
|
111 | + if (!empty($this->adapter)) { |
|
112 | 112 | return $this->adapter; |
113 | 113 | } |
114 | 114 | |
115 | - $validHandlers = $this->config['valid_handlers'] ?? self::$validHandlers; |
|
115 | + $validHandlers = $this->config[ 'valid_handlers' ] ?? self::$validHandlers; |
|
116 | 116 | |
117 | - if (empty($validHandlers) || ! is_array($validHandlers)) { |
|
117 | + if (empty($validHandlers) || !is_array($validHandlers)) { |
|
118 | 118 | throw new InvalidArgumentException('La configuration du cache doit avoir un tableau de $valid_handlers.'); |
119 | 119 | } |
120 | 120 | |
121 | - $handler = $this->config['handler'] ?? null; |
|
122 | - $fallback = $this->config['fallback_handler'] ?? null; |
|
121 | + $handler = $this->config[ 'handler' ] ?? null; |
|
122 | + $fallback = $this->config[ 'fallback_handler' ] ?? null; |
|
123 | 123 | |
124 | 124 | if (empty($handler)) { |
125 | 125 | throw new InvalidArgumentException('La configuration du cache doit avoir un ensemble de gestionnaires.'); |
126 | 126 | } |
127 | 127 | |
128 | - if (! array_key_exists($handler, $validHandlers)) { |
|
128 | + if (!array_key_exists($handler, $validHandlers)) { |
|
129 | 129 | throw new InvalidArgumentException('La configuration du cache a un gestionnaire non valide spécifié.'); |
130 | 130 | } |
131 | 131 | |
132 | - $adapter = new $validHandlers[$handler](); |
|
133 | - if (! ($adapter instanceof BaseHandler)) { |
|
132 | + $adapter = new $validHandlers[ $handler ](); |
|
133 | + if (!($adapter instanceof BaseHandler)) { |
|
134 | 134 | if (empty($fallback)) { |
135 | 135 | $adapter = new Dummy(); |
136 | - } elseif (! array_key_exists($fallback, $validHandlers)) { |
|
136 | + } elseif (!array_key_exists($fallback, $validHandlers)) { |
|
137 | 137 | throw new InvalidArgumentException('La configuration du cache a un gestionnaire de secours non valide spécifié.'); |
138 | 138 | } else { |
139 | - $adapter = new $validHandlers[$fallback](); |
|
139 | + $adapter = new $validHandlers[ $fallback ](); |
|
140 | 140 | } |
141 | 141 | } |
142 | 142 | |
143 | - if (! ($adapter instanceof BaseHandler)) { |
|
143 | + if (!($adapter instanceof BaseHandler)) { |
|
144 | 144 | throw new InvalidArgumentException('Le gestionnaire de cache doit utiliser BlitzPHP\Cache\Handlers\BaseHandler comme classe de base.'); |
145 | 145 | } |
146 | 146 | |
147 | - if (isset($this->config[$handler]) && is_array($this->config[$handler])) { |
|
148 | - $this->config = array_merge($this->config, $this->config[$handler]); |
|
149 | - unset($this->config[$handler]); |
|
147 | + if (isset($this->config[ $handler ]) && is_array($this->config[ $handler ])) { |
|
148 | + $this->config = array_merge($this->config, $this->config[ $handler ]); |
|
149 | + unset($this->config[ $handler ]); |
|
150 | 150 | } |
151 | 151 | |
152 | - if (! $adapter->init($this->config)) { |
|
152 | + if (!$adapter->init($this->config)) { |
|
153 | 153 | throw new RuntimeException( |
154 | 154 | sprintf( |
155 | 155 | 'Le moteur de cache %s n\'est pas correctement configuré. Consultez le journal des erreurs pour plus d\'informations.', |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | * |
180 | 180 | * @return bool Vrai si les données ont été mises en cache avec succès, faux en cas d'échec |
181 | 181 | */ |
182 | - public function write(string $key, mixed $value, null|DateInterval|int $ttl = null): bool |
|
182 | + public function write(string $key, mixed $value, null | DateInterval | int $ttl = null): bool |
|
183 | 183 | { |
184 | 184 | if (is_resource($value)) { |
185 | 185 | return false; |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | /** |
205 | 205 | * {@inheritDoc} |
206 | 206 | */ |
207 | - public function set(string $key, mixed $value, null|DateInterval|int $ttl = null): bool |
|
207 | + public function set(string $key, mixed $value, null | DateInterval | int $ttl = null): bool |
|
208 | 208 | { |
209 | 209 | return $this->write($key, $value, $ttl); |
210 | 210 | } |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | * |
230 | 230 | * @throws InvalidArgumentException |
231 | 231 | */ |
232 | - public function writeMany(iterable $data, null|DateInterval|int $ttl = null): bool |
|
232 | + public function writeMany(iterable $data, null | DateInterval | int $ttl = null): bool |
|
233 | 233 | { |
234 | 234 | return $this->factory()->setMultiple($data, $ttl); |
235 | 235 | } |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | /** |
238 | 238 | * {@inheritDoc} |
239 | 239 | */ |
240 | - public function setMultiple(iterable $values, null|DateInterval|int $ttl = null): bool |
|
240 | + public function setMultiple(iterable $values, null | DateInterval | int $ttl = null): bool |
|
241 | 241 | { |
242 | 242 | return $this->writeMany($values, $ttl); |
243 | 243 | } |
@@ -487,7 +487,7 @@ discard block |
||
487 | 487 | * @return mixed Si la clé est trouvée : les données en cache. |
488 | 488 | * Si la clé n'est pas trouvée, la valeur renvoyée par le callable. |
489 | 489 | */ |
490 | - public function remember(string $key, callable|DateInterval|int|null $ttl, callable $callable = null): mixed |
|
490 | + public function remember(string $key, callable | DateInterval | int | null $ttl, callable $callable = null): mixed |
|
491 | 491 | { |
492 | 492 | return $this->factory()->remember($key, $ttl, $callable); |
493 | 493 | } |
@@ -539,7 +539,7 @@ discard block |
||
539 | 539 | */ |
540 | 540 | public function pull(string $key, $default = null) |
541 | 541 | { |
542 | - return Helpers::tap($this->read($key, $default), function () use ($key) { |
|
542 | + return Helpers::tap($this->read($key, $default), function() use ($key) { |
|
543 | 543 | $this->delete($key); |
544 | 544 | }); |
545 | 545 | } |
@@ -554,7 +554,7 @@ discard block |
||
554 | 554 | */ |
555 | 555 | public function pullMany(iterable $keys, $default = null) |
556 | 556 | { |
557 | - return Helpers::tap($this->readMany($keys, $default), function () use ($keys) { |
|
557 | + return Helpers::tap($this->readMany($keys, $default), function() use ($keys) { |
|
558 | 558 | $this->deleteMany($keys); |
559 | 559 | }); |
560 | 560 | } |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | */ |
61 | 61 | protected array $_defaultConfig = [ |
62 | 62 | 'duration' => 3600, |
63 | - 'groups' => [], |
|
63 | + 'groups' => [ ], |
|
64 | 64 | 'prefix' => 'blitz_', |
65 | 65 | 'warnOnWriteFailures' => true, |
66 | 66 | ]; |
@@ -81,16 +81,16 @@ discard block |
||
81 | 81 | * |
82 | 82 | * @return bool Vrai si le moteur a été initialisé avec succès, faux sinon |
83 | 83 | */ |
84 | - public function init(array $config = []): bool |
|
84 | + public function init(array $config = [ ]): bool |
|
85 | 85 | { |
86 | 86 | $this->setConfig($config); |
87 | 87 | |
88 | - if (! empty($this->_config['groups'])) { |
|
89 | - sort($this->_config['groups']); |
|
90 | - $this->_groupPrefix = str_repeat('%s_', count($this->_config['groups'])); |
|
88 | + if (!empty($this->_config[ 'groups' ])) { |
|
89 | + sort($this->_config[ 'groups' ]); |
|
90 | + $this->_groupPrefix = str_repeat('%s_', count($this->_config[ 'groups' ])); |
|
91 | 91 | } |
92 | - if (! is_numeric($this->_config['duration'])) { |
|
93 | - $this->_config['duration'] = strtotime($this->_config['duration']) - time(); |
|
92 | + if (!is_numeric($this->_config[ 'duration' ])) { |
|
93 | + $this->_config[ 'duration' ] = strtotime($this->_config[ 'duration' ]) - time(); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | return true; |
@@ -111,13 +111,13 @@ discard block |
||
111 | 111 | */ |
112 | 112 | public function ensureValidKey(string $key): void |
113 | 113 | { |
114 | - if (! is_string($key) || $key === '') { |
|
114 | + if (!is_string($key) || $key === '') { |
|
115 | 115 | throw new InvalidArgumentException('Une clé de cache doit être une chaîne non vide.'); |
116 | 116 | } |
117 | 117 | |
118 | 118 | $reserved = self::$reservedCharacters; |
119 | 119 | if ($reserved && strpbrk($key, $reserved) !== false) { |
120 | - throw new InvalidArgumentException('La clé de cache contient des caractères réservés ' . $reserved); |
|
120 | + throw new InvalidArgumentException('La clé de cache contient des caractères réservés '.$reserved); |
|
121 | 121 | } |
122 | 122 | } |
123 | 123 | |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | */ |
132 | 132 | protected function ensureValidType($iterable, string $check = self::CHECK_VALUE): void |
133 | 133 | { |
134 | - if (! is_iterable($iterable)) { |
|
134 | + if (!is_iterable($iterable)) { |
|
135 | 135 | throw new InvalidArgumentException(sprintf( |
136 | 136 | 'Un cache %s doit être soit un tableau soit un Traversable.', |
137 | 137 | $check === self::CHECK_VALUE ? 'key set' : 'set' |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | * @return mixed Si la clé est trouvée : les données en cache. |
176 | 176 | * Si la clé n'est pas trouvée, la valeur renvoyée par le callable. |
177 | 177 | */ |
178 | - public function remember(string $key, callable|DateInterval|int|null $ttl, callable $callable = null): mixed |
|
178 | + public function remember(string $key, callable | DateInterval | int | null $ttl, callable $callable = null): mixed |
|
179 | 179 | { |
180 | 180 | if (is_callable($ttl)) { |
181 | 181 | $callable = $ttl; |
@@ -218,10 +218,10 @@ discard block |
||
218 | 218 | { |
219 | 219 | $this->ensureValidType($keys); |
220 | 220 | |
221 | - $results = []; |
|
221 | + $results = [ ]; |
|
222 | 222 | |
223 | 223 | foreach ($keys as $key) { |
224 | - $results[$key] = $this->get($key, $default); |
|
224 | + $results[ $key ] = $this->get($key, $default); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | return $results; |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | * @throws InvalidArgumentException Si $values n'est ni un tableau ni un Traversable, |
241 | 241 | * ou si l'une des valeurs $ n'est pas une valeur légale. |
242 | 242 | */ |
243 | - public function setMultiple(iterable $values, null|DateInterval|int $ttl = null): bool |
|
243 | + public function setMultiple(iterable $values, null | DateInterval | int $ttl = null): bool |
|
244 | 244 | { |
245 | 245 | $this->ensureValidType($values, self::CHECK_KEY); |
246 | 246 | |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | $result = true; |
287 | 287 | |
288 | 288 | foreach ($keys as $key) { |
289 | - if (! $this->delete($key)) { |
|
289 | + if (!$this->delete($key)) { |
|
290 | 290 | $result = false; |
291 | 291 | } |
292 | 292 | } |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | * |
326 | 326 | * @return bool Vrai en cas de succès et faux en cas d'échec. |
327 | 327 | */ |
328 | - abstract public function set(string $key, mixed $value, null|DateInterval|int $ttl = null): bool; |
|
328 | + abstract public function set(string $key, mixed $value, null | DateInterval | int $ttl = null): bool; |
|
329 | 329 | |
330 | 330 | /** |
331 | 331 | * {@inheritDoc} |
@@ -382,7 +382,7 @@ discard block |
||
382 | 382 | */ |
383 | 383 | public function groups(): array |
384 | 384 | { |
385 | - return $this->_config['groups']; |
|
385 | + return $this->_config[ 'groups' ]; |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | /** |
@@ -407,7 +407,7 @@ discard block |
||
407 | 407 | } |
408 | 408 | $key = preg_replace('/[\s]+/', '_', $key); |
409 | 409 | |
410 | - return $this->_config['prefix'] . $prefix . $key; |
|
410 | + return $this->_config[ 'prefix' ].$prefix.$key; |
|
411 | 411 | } |
412 | 412 | |
413 | 413 | /** |
@@ -429,10 +429,10 @@ discard block |
||
429 | 429 | * @param DateInterval|int|null $ttl La valeur TTL de cet élément. Si null est envoyé, |
430 | 430 | * La durée par défaut du conducteur sera utilisée. |
431 | 431 | */ |
432 | - protected function duration(null|DateInterval|int $ttl): int |
|
432 | + protected function duration(null | DateInterval | int $ttl): int |
|
433 | 433 | { |
434 | 434 | if ($ttl === null) { |
435 | - return $this->_config['duration']; |
|
435 | + return $this->_config[ 'duration' ]; |
|
436 | 436 | } |
437 | 437 | |
438 | 438 | if (is_int($ttl)) { |