@@ -31,10 +31,10 @@ discard block |
||
31 | 31 | |
32 | 32 | /** |
33 | 33 | * @param bool|string[] $cacheQueryString Whether to take the URL query string into consideration when generating output cache files. |
34 | - * Valid options are: |
|
34 | + * Valid options are: |
|
35 | 35 | * false = Disabled |
36 | 36 | * true = Enabled, take all query parameters into account. |
37 | - * Please be aware that this may result in numerous cache |
|
37 | + * Please be aware that this may result in numerous cache |
|
38 | 38 | * files generated for the same page over and over again. |
39 | 39 | * array('q') = Enabled, but only take into account the specified list of query parameters. |
40 | 40 | */ |
@@ -58,12 +58,12 @@ discard block |
||
58 | 58 | { |
59 | 59 | $uri = clone $request->getUri(); |
60 | 60 | |
61 | - // @todo implementation de la recuperation des queriestring |
|
61 | + // @todo implementation de la recuperation des queriestring |
|
62 | 62 | /* $query = $this->cacheQueryString |
63 | 63 | ? $uri->getQuery(is_array($this->cacheQueryString) ? ['only' => $this->cacheQueryString] : []) |
64 | 64 | : ''; */ |
65 | 65 | |
66 | - $query = ''; |
|
66 | + $query = ''; |
|
67 | 67 | |
68 | 68 | return md5($uri->withFragment('')->withQuery($query)); |
69 | 69 | } |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | return true; |
78 | 78 | } |
79 | 79 | |
80 | - $headers = []; |
|
80 | + $headers = []; |
|
81 | 81 | |
82 | 82 | foreach (array_keys($response->getHeaders()) as $header) { |
83 | 83 | $headers[$header] = $response->getHeaderLine($header); |
@@ -95,17 +95,17 @@ discard block |
||
95 | 95 | */ |
96 | 96 | public function get(ServerRequestInterface $request, ResponseInterface $response): ?ResponseInterface |
97 | 97 | { |
98 | - if ($cachedResponse = $this->cache->get($this->generateCacheKey($request))) { |
|
98 | + if ($cachedResponse = $this->cache->get($this->generateCacheKey($request))) { |
|
99 | 99 | $cachedResponse = unserialize($cachedResponse); |
100 | 100 | |
101 | - if (! is_array($cachedResponse) || ! isset($cachedResponse['output']) || ! isset($cachedResponse['headers'])) { |
|
101 | + if (! is_array($cachedResponse) || ! isset($cachedResponse['output']) || ! isset($cachedResponse['headers'])) { |
|
102 | 102 | throw new Exception('Erreur lors de la désérialisation du cache de page'); |
103 | 103 | } |
104 | 104 | |
105 | 105 | $headers = $cachedResponse['headers']; |
106 | 106 | $output = $cachedResponse['output']; |
107 | 107 | |
108 | - // Effacer tous les en-têtes par défaut |
|
108 | + // Effacer tous les en-têtes par défaut |
|
109 | 109 | foreach (array_keys($response->getHeaders()) as $key) { |
110 | 110 | $response = $response->withoutHeader($key); |
111 | 111 | } |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | $response = $response->withHeader($name, $value); |
116 | 116 | } |
117 | 117 | |
118 | - return $response->withBody(to_stream($output)); |
|
118 | + return $response->withBody(to_stream($output)); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | return null; |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | * files generated for the same page over and over again. |
39 | 39 | * array('q') = Enabled, but only take into account the specified list of query parameters. |
40 | 40 | */ |
41 | - public function __construct(private CacheInterface $cache, private bool|array $cacheQueryString = false) |
|
41 | + public function __construct(private CacheInterface $cache, private bool | array $cacheQueryString = false) |
|
42 | 42 | { |
43 | 43 | } |
44 | 44 | |
@@ -77,15 +77,15 @@ discard block |
||
77 | 77 | return true; |
78 | 78 | } |
79 | 79 | |
80 | - $headers = []; |
|
80 | + $headers = [ ]; |
|
81 | 81 | |
82 | 82 | foreach (array_keys($response->getHeaders()) as $header) { |
83 | - $headers[$header] = $response->getHeaderLine($header); |
|
83 | + $headers[ $header ] = $response->getHeaderLine($header); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | return $this->cache->set( |
87 | 87 | $this->generateCacheKey($request), |
88 | - serialize(['headers' => $headers, 'output' => $response->getBody()->getContents()]), |
|
88 | + serialize([ 'headers' => $headers, 'output' => $response->getBody()->getContents() ]), |
|
89 | 89 | $this->ttl |
90 | 90 | ); |
91 | 91 | } |
@@ -98,12 +98,12 @@ discard block |
||
98 | 98 | if ($cachedResponse = $this->cache->get($this->generateCacheKey($request))) { |
99 | 99 | $cachedResponse = unserialize($cachedResponse); |
100 | 100 | |
101 | - if (! is_array($cachedResponse) || ! isset($cachedResponse['output']) || ! isset($cachedResponse['headers'])) { |
|
101 | + if (!is_array($cachedResponse) || !isset($cachedResponse[ 'output' ]) || !isset($cachedResponse[ 'headers' ])) { |
|
102 | 102 | throw new Exception('Erreur lors de la désérialisation du cache de page'); |
103 | 103 | } |
104 | 104 | |
105 | - $headers = $cachedResponse['headers']; |
|
106 | - $output = $cachedResponse['output']; |
|
105 | + $headers = $cachedResponse[ 'headers' ]; |
|
106 | + $output = $cachedResponse[ 'output' ]; |
|
107 | 107 | |
108 | 108 | // Effacer tous les en-têtes par défaut |
109 | 109 | foreach (array_keys($response->getHeaders()) as $key) { |
@@ -141,10 +141,10 @@ |
||
141 | 141 | throw new InvalidArgumentException('Le gestionnaire de cache doit utiliser BlitzPHP\Cache\Handlers\BaseHandler comme classe de base.'); |
142 | 142 | } |
143 | 143 | |
144 | - if (isset($this->config[$handler]) && is_array($this->config[$handler])) { |
|
145 | - $this->config = array_merge($this->config, $this->config[$handler]); |
|
146 | - unset($this->config[$handler]); |
|
147 | - } |
|
144 | + if (isset($this->config[$handler]) && is_array($this->config[$handler])) { |
|
145 | + $this->config = array_merge($this->config, $this->config[$handler]); |
|
146 | + unset($this->config[$handler]); |
|
147 | + } |
|
148 | 148 | |
149 | 149 | if (! $adapter->init($this->config)) { |
150 | 150 | throw new RuntimeException( |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | /** |
72 | 72 | * Configuration des caches |
73 | 73 | */ |
74 | - protected array $config = []; |
|
74 | + protected array $config = [ ]; |
|
75 | 75 | |
76 | 76 | /** |
77 | 77 | * Adapter a utiliser pour la mise en cache |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | /** |
82 | 82 | * Constructeur |
83 | 83 | */ |
84 | - public function __construct(array $config = []) |
|
84 | + public function __construct(array $config = [ ]) |
|
85 | 85 | { |
86 | 86 | $this->setConfig($config); |
87 | 87 | } |
@@ -102,51 +102,51 @@ discard block |
||
102 | 102 | */ |
103 | 103 | protected function factory(): CacheInterface |
104 | 104 | { |
105 | - if (! static::$_enabled) { |
|
105 | + if (!static::$_enabled) { |
|
106 | 106 | return new Dummy(); |
107 | 107 | } |
108 | - if (! empty($this->adapter)) { |
|
108 | + if (!empty($this->adapter)) { |
|
109 | 109 | return $this->adapter; |
110 | 110 | } |
111 | 111 | |
112 | - $validHandlers = $this->config['valid_handlers'] ?? self::$validHandlers; |
|
112 | + $validHandlers = $this->config[ 'valid_handlers' ] ?? self::$validHandlers; |
|
113 | 113 | |
114 | - if (empty($validHandlers) || ! is_array($validHandlers)) { |
|
114 | + if (empty($validHandlers) || !is_array($validHandlers)) { |
|
115 | 115 | throw new InvalidArgumentException('La configuration du cache doit avoir un tableau de $valid_handlers.'); |
116 | 116 | } |
117 | 117 | |
118 | - $handler = $this->config['handler'] ?? null; |
|
119 | - $fallback = $this->config['fallback_handler'] ?? null; |
|
118 | + $handler = $this->config[ 'handler' ] ?? null; |
|
119 | + $fallback = $this->config[ 'fallback_handler' ] ?? null; |
|
120 | 120 | |
121 | 121 | if (empty($handler)) { |
122 | 122 | throw new InvalidArgumentException('La configuration du cache doit avoir un ensemble de gestionnaires.'); |
123 | 123 | } |
124 | 124 | |
125 | - if (! array_key_exists($handler, $validHandlers)) { |
|
125 | + if (!array_key_exists($handler, $validHandlers)) { |
|
126 | 126 | throw new InvalidArgumentException('La configuration du cache a un gestionnaire non valide spécifié.'); |
127 | 127 | } |
128 | 128 | |
129 | - $adapter = new $validHandlers[$handler](); |
|
130 | - if (! ($adapter instanceof BaseHandler)) { |
|
129 | + $adapter = new $validHandlers[ $handler ](); |
|
130 | + if (!($adapter instanceof BaseHandler)) { |
|
131 | 131 | if (empty($fallback)) { |
132 | 132 | $adapter = new Dummy(); |
133 | - } elseif (! array_key_exists($fallback, $validHandlers)) { |
|
133 | + } elseif (!array_key_exists($fallback, $validHandlers)) { |
|
134 | 134 | throw new InvalidArgumentException('La configuration du cache a un gestionnaire de secours non valide spécifié.'); |
135 | 135 | } else { |
136 | - $adapter = new $validHandlers[$fallback](); |
|
136 | + $adapter = new $validHandlers[ $fallback ](); |
|
137 | 137 | } |
138 | 138 | } |
139 | 139 | |
140 | - if (! ($adapter instanceof BaseHandler)) { |
|
140 | + if (!($adapter instanceof BaseHandler)) { |
|
141 | 141 | throw new InvalidArgumentException('Le gestionnaire de cache doit utiliser BlitzPHP\Cache\Handlers\BaseHandler comme classe de base.'); |
142 | 142 | } |
143 | 143 | |
144 | - if (isset($this->config[$handler]) && is_array($this->config[$handler])) { |
|
145 | - $this->config = array_merge($this->config, $this->config[$handler]); |
|
146 | - unset($this->config[$handler]); |
|
144 | + if (isset($this->config[ $handler ]) && is_array($this->config[ $handler ])) { |
|
145 | + $this->config = array_merge($this->config, $this->config[ $handler ]); |
|
146 | + unset($this->config[ $handler ]); |
|
147 | 147 | } |
148 | 148 | |
149 | - if (! $adapter->init($this->config)) { |
|
149 | + if (!$adapter->init($this->config)) { |
|
150 | 150 | throw new RuntimeException( |
151 | 151 | sprintf( |
152 | 152 | 'Le moteur de cache %s n\'est pas correctement configuré. Consultez le journal des erreurs pour plus d\'informations.', |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | * |
177 | 177 | * @return bool Vrai si les données ont été mises en cache avec succès, faux en cas d'échec |
178 | 178 | */ |
179 | - public function write(string $key, mixed $value, DateInterval|int|null $ttl = null): bool |
|
179 | + public function write(string $key, mixed $value, DateInterval | int | null $ttl = null): bool |
|
180 | 180 | { |
181 | 181 | if (is_resource($value)) { |
182 | 182 | return false; |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | /** |
202 | 202 | * {@inheritDoc} |
203 | 203 | */ |
204 | - public function set(string $key, mixed $value, DateInterval|int|null $ttl = null): bool |
|
204 | + public function set(string $key, mixed $value, DateInterval | int | null $ttl = null): bool |
|
205 | 205 | { |
206 | 206 | return $this->write($key, $value, $ttl); |
207 | 207 | } |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | * |
227 | 227 | * @throws InvalidArgumentException |
228 | 228 | */ |
229 | - public function writeMany(iterable $data, DateInterval|int|null $ttl = null): bool |
|
229 | + public function writeMany(iterable $data, DateInterval | int | null $ttl = null): bool |
|
230 | 230 | { |
231 | 231 | return $this->factory()->setMultiple($data, $ttl); |
232 | 232 | } |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | /** |
235 | 235 | * {@inheritDoc} |
236 | 236 | */ |
237 | - public function setMultiple(iterable $values, DateInterval|int|null $ttl = null): bool |
|
237 | + public function setMultiple(iterable $values, DateInterval | int | null $ttl = null): bool |
|
238 | 238 | { |
239 | 239 | return $this->writeMany($values, $ttl); |
240 | 240 | } |