@@ -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 | } |
@@ -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 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 (strpos($server, $socketTransport) === 0) { |
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,17 +323,17 @@ 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); |
333 | - $return = []; |
|
333 | + $return = [ ]; |
|
334 | 334 | |
335 | 335 | foreach ($cacheKeys as $original => $prefixed) { |
336 | - $return[$original] = $values[$prefixed] ?? $default; |
|
336 | + $return[ $original ] = $values[ $prefixed ] ?? $default; |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | return $return; |
@@ -368,10 +368,10 @@ discard block |
||
368 | 368 | */ |
369 | 369 | public function deleteMultiple(iterable $keys): bool |
370 | 370 | { |
371 | - $cacheKeys = []; |
|
371 | + $cacheKeys = [ ]; |
|
372 | 372 | |
373 | 373 | foreach ($keys as $key) { |
374 | - $cacheKeys[] = $this->_key($key); |
|
374 | + $cacheKeys[ ] = $this->_key($key); |
|
375 | 375 | } |
376 | 376 | |
377 | 377 | return (bool) $this->_Memcached->deleteMulti($cacheKeys); |
@@ -388,7 +388,7 @@ discard block |
||
388 | 388 | } |
389 | 389 | |
390 | 390 | foreach ($keys as $key) { |
391 | - if (strpos($key, $this->_config['prefix']) === 0) { |
|
391 | + if (strpos($key, $this->_config[ 'prefix' ]) === 0) { |
|
392 | 392 | $this->_Memcached->delete($key); |
393 | 393 | } |
394 | 394 | } |
@@ -401,7 +401,7 @@ discard block |
||
401 | 401 | */ |
402 | 402 | public function add(string $key, mixed $value): bool |
403 | 403 | { |
404 | - $duration = $this->_config['duration']; |
|
404 | + $duration = $this->_config[ 'duration' ]; |
|
405 | 405 | $key = $this->_key($key); |
406 | 406 | |
407 | 407 | return $this->_Memcached->add($key, $value, $duration); |
@@ -413,27 +413,27 @@ discard block |
||
413 | 413 | public function groups(): array |
414 | 414 | { |
415 | 415 | if (empty($this->_compiledGroupNames)) { |
416 | - foreach ($this->_config['groups'] as $group) { |
|
417 | - $this->_compiledGroupNames[] = $this->_config['prefix'] . $group; |
|
416 | + foreach ($this->_config[ 'groups' ] as $group) { |
|
417 | + $this->_compiledGroupNames[ ] = $this->_config[ 'prefix' ].$group; |
|
418 | 418 | } |
419 | 419 | } |
420 | 420 | |
421 | - $groups = $this->_Memcached->getMulti($this->_compiledGroupNames) ?: []; |
|
422 | - if (count($groups) !== count($this->_config['groups'])) { |
|
421 | + $groups = $this->_Memcached->getMulti($this->_compiledGroupNames) ?: [ ]; |
|
422 | + if (count($groups) !== count($this->_config[ 'groups' ])) { |
|
423 | 423 | foreach ($this->_compiledGroupNames as $group) { |
424 | - if (! isset($groups[$group])) { |
|
424 | + if (!isset($groups[ $group ])) { |
|
425 | 425 | $this->_Memcached->set($group, 1, 0); |
426 | - $groups[$group] = 1; |
|
426 | + $groups[ $group ] = 1; |
|
427 | 427 | } |
428 | 428 | } |
429 | 429 | ksort($groups); |
430 | 430 | } |
431 | 431 | |
432 | - $result = []; |
|
432 | + $result = [ ]; |
|
433 | 433 | $groups = array_values($groups); |
434 | 434 | |
435 | - foreach ($this->_config['groups'] as $i => $group) { |
|
436 | - $result[] = $group . $groups[$i]; |
|
435 | + foreach ($this->_config[ 'groups' ] as $i => $group) { |
|
436 | + $result[ ] = $group.$groups[ $i ]; |
|
437 | 437 | } |
438 | 438 | |
439 | 439 | return $result; |
@@ -444,6 +444,6 @@ discard block |
||
444 | 444 | */ |
445 | 445 | public function clearGroup(string $group): bool |
446 | 446 | { |
447 | - return (bool) $this->_Memcached->increment($this->_config['prefix'] . $group); |
|
447 | + return (bool) $this->_Memcached->increment($this->_config[ 'prefix' ].$group); |
|
448 | 448 | } |
449 | 449 | } |
@@ -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 | /** |
@@ -89,9 +89,9 @@ discard block |
||
89 | 89 | $this->set($key, 0); |
90 | 90 | } |
91 | 91 | $key = $this->_key($key); |
92 | - $this->data[$key]['val'] -= $offset; |
|
92 | + $this->data[ $key ][ 'val' ] -= $offset; |
|
93 | 93 | |
94 | - return $this->data[$key]['val']; |
|
94 | + return $this->data[ $key ][ 'val' ]; |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | public function delete(string $key): bool |
101 | 101 | { |
102 | 102 | $key = $this->_key($key); |
103 | - unset($this->data[$key]); |
|
103 | + unset($this->data[ $key ]); |
|
104 | 104 | |
105 | 105 | return true; |
106 | 106 | } |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | */ |
111 | 111 | public function clear(): bool |
112 | 112 | { |
113 | - $this->data = []; |
|
113 | + $this->data = [ ]; |
|
114 | 114 | |
115 | 115 | return true; |
116 | 116 | } |
@@ -120,15 +120,15 @@ discard block |
||
120 | 120 | */ |
121 | 121 | public function groups(): array |
122 | 122 | { |
123 | - $result = []; |
|
123 | + $result = [ ]; |
|
124 | 124 | |
125 | - foreach ($this->_config['groups'] as $group) { |
|
126 | - $key = $this->_config['prefix'] . $group; |
|
127 | - if (! isset($this->data[$key])) { |
|
128 | - $this->data[$key] = ['exp' => PHP_INT_MAX, 'val' => 1]; |
|
125 | + foreach ($this->_config[ 'groups' ] as $group) { |
|
126 | + $key = $this->_config[ 'prefix' ].$group; |
|
127 | + if (!isset($this->data[ $key ])) { |
|
128 | + $this->data[ $key ] = [ 'exp' => PHP_INT_MAX, 'val' => 1 ]; |
|
129 | 129 | } |
130 | - $value = $this->data[$key]['val']; |
|
131 | - $result[] = $group . $value; |
|
130 | + $value = $this->data[ $key ][ 'val' ]; |
|
131 | + $result[ ] = $group.$value; |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | return $result; |
@@ -139,9 +139,9 @@ discard block |
||
139 | 139 | */ |
140 | 140 | public function clearGroup(string $group): bool |
141 | 141 | { |
142 | - $key = $this->_config['prefix'] . $group; |
|
143 | - if (isset($this->data[$key])) { |
|
144 | - $this->data[$key]['val']++; |
|
142 | + $key = $this->_config[ 'prefix' ].$group; |
|
143 | + if (isset($this->data[ $key ])) { |
|
144 | + $this->data[ $key ][ 'val' ]++; |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | return true; |
@@ -26,14 +26,14 @@ discard block |
||
26 | 26 | * |
27 | 27 | * @var 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 (strpos($key['info'], $this->_config['prefix']) === 0) { |
|
127 | - apcu_delete($key['info']); |
|
125 | + foreach ($cache[ 'cache_list' ] as $key) { |
|
126 | + if (strpos($key[ 'info' ], $this->_config[ 'prefix' ]) === 0) { |
|
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 | } |
@@ -153,33 +153,33 @@ discard block |
||
153 | 153 | public function groups(): array |
154 | 154 | { |
155 | 155 | if (empty($this->_compiledGroupNames)) { |
156 | - foreach ($this->_config['groups'] as $group) { |
|
157 | - $this->_compiledGroupNames[] = $this->_config['prefix'] . $group; |
|
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 | } |
@@ -25,14 +25,14 @@ discard block |
||
25 | 25 | * Contient les noms de groupe compilés |
26 | 26 | * (préfixé par le préfixe de configuration global) |
27 | 27 | */ |
28 | - protected array $_compiledGroupNames = []; |
|
28 | + protected array $_compiledGroupNames = [ ]; |
|
29 | 29 | |
30 | 30 | /** |
31 | 31 | * {@inheritDoc} |
32 | 32 | */ |
33 | - public function init(array $config = []): bool |
|
33 | + public function init(array $config = [ ]): bool |
|
34 | 34 | { |
35 | - if (! extension_loaded('wincache')) { |
|
35 | + if (!extension_loaded('wincache')) { |
|
36 | 36 | throw new RuntimeException('L\'extension `wincache` doit être activée pour utiliser WincacheHandler.'); |
37 | 37 | } |
38 | 38 | |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | /** |
45 | 45 | * {@inheritDoc} |
46 | 46 | */ |
47 | - public function set(string $key, mixed $value, DateInterval|int|null $ttl = null): bool |
|
47 | + public function set(string $key, mixed $value, DateInterval | int | null $ttl = null): bool |
|
48 | 48 | { |
49 | 49 | $key = $this->_key($key); |
50 | 50 | $duration = $this->duration($ttl); |
@@ -101,12 +101,12 @@ discard block |
||
101 | 101 | public function clear(): bool |
102 | 102 | { |
103 | 103 | $info = wincache_ucache_info(); |
104 | - $cacheKeys = $info['ucache_entries']; |
|
104 | + $cacheKeys = $info[ 'ucache_entries' ]; |
|
105 | 105 | unset($info); |
106 | 106 | |
107 | 107 | foreach ($cacheKeys as $key) { |
108 | - if (strpos($key['key_name'], $this->_config['prefix']) === 0) { |
|
109 | - wincache_ucache_delete($key['key_name']); |
|
108 | + if (strpos($key[ 'key_name' ], $this->_config[ 'prefix' ]) === 0) { |
|
109 | + wincache_ucache_delete($key[ 'key_name' ]); |
|
110 | 110 | } |
111 | 111 | } |
112 | 112 | |
@@ -119,27 +119,27 @@ discard block |
||
119 | 119 | public function groups(): array |
120 | 120 | { |
121 | 121 | if (empty($this->_compiledGroupNames)) { |
122 | - foreach ($this->_config['groups'] as $group) { |
|
123 | - $this->_compiledGroupNames[] = $this->_config['prefix'] . $group; |
|
122 | + foreach ($this->_config[ 'groups' ] as $group) { |
|
123 | + $this->_compiledGroupNames[ ] = $this->_config[ 'prefix' ].$group; |
|
124 | 124 | } |
125 | 125 | } |
126 | 126 | |
127 | 127 | $groups = wincache_ucache_get($this->_compiledGroupNames); |
128 | - if (count($groups) !== count($this->_config['groups'])) { |
|
128 | + if (count($groups) !== count($this->_config[ 'groups' ])) { |
|
129 | 129 | foreach ($this->_compiledGroupNames as $group) { |
130 | - if (! isset($groups[$group])) { |
|
130 | + if (!isset($groups[ $group ])) { |
|
131 | 131 | wincache_ucache_set($group, 1); |
132 | - $groups[$group] = 1; |
|
132 | + $groups[ $group ] = 1; |
|
133 | 133 | } |
134 | 134 | } |
135 | 135 | ksort($groups); |
136 | 136 | } |
137 | 137 | |
138 | - $result = []; |
|
138 | + $result = [ ]; |
|
139 | 139 | $groups = array_values($groups); |
140 | 140 | |
141 | - foreach ($this->_config['groups'] as $i => $group) { |
|
142 | - $result[] = $group . $groups[$i]; |
|
141 | + foreach ($this->_config[ 'groups' ] as $i => $group) { |
|
142 | + $result[ ] = $group.$groups[ $i ]; |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | return $result; |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | public function clearGroup(string $group): bool |
152 | 152 | { |
153 | 153 | $success = false; |
154 | - wincache_ucache_inc($this->_config['prefix'] . $group, 1, $success); |
|
154 | + wincache_ucache_inc($this->_config[ 'prefix' ].$group, 1, $success); |
|
155 | 155 | |
156 | 156 | return $success; |
157 | 157 | } |