N°6934 - Symfony 6.4 - upgrade Symfony bundles to 6.4 (#580)

* Update Symfony lib to version ~6.4.0
* Update code missing return type
* Add an iTop general configuration entry to store application secret (Symfony mandatory parameter)
* Use dependency injection in ExceptionListener & UserProvider classes
This commit is contained in:
bdalsass
2023-12-05 13:56:56 +01:00
committed by GitHub
parent 863ab4560c
commit 27ce51ab07
1392 changed files with 44869 additions and 27799 deletions

View File

@@ -26,10 +26,10 @@ class Store implements StoreInterface
{
protected $root;
/** @var \SplObjectStorage<Request, string> */
private $keyCache;
private \SplObjectStorage $keyCache;
/** @var array<string, resource> */
private $locks = [];
private $options;
private array $locks = [];
private array $options;
/**
* Constructor.
@@ -55,6 +55,8 @@ class Store implements StoreInterface
/**
* Cleanups storage.
*
* @return void
*/
public function cleanup()
{
@@ -72,7 +74,7 @@ class Store implements StoreInterface
*
* @return bool|string true if the lock is acquired, the path to the current lock otherwise
*/
public function lock(Request $request)
public function lock(Request $request): bool|string
{
$key = $this->getCacheKey($request);
@@ -99,7 +101,7 @@ class Store implements StoreInterface
*
* @return bool False if the lock file does not exist or cannot be unlocked, true otherwise
*/
public function unlock(Request $request)
public function unlock(Request $request): bool
{
$key = $this->getCacheKey($request);
@@ -114,7 +116,7 @@ class Store implements StoreInterface
return false;
}
public function isLocked(Request $request)
public function isLocked(Request $request): bool
{
$key = $this->getCacheKey($request);
@@ -136,10 +138,8 @@ class Store implements StoreInterface
/**
* Locates a cached Response for the Request provided.
*
* @return Response|null
*/
public function lookup(Request $request)
public function lookup(Request $request): ?Response
{
$key = $this->getCacheKey($request);
@@ -178,11 +178,9 @@ class Store implements StoreInterface
* Existing entries are read and any that match the response are removed. This
* method calls write with the new list of cache entries.
*
* @return string
*
* @throws \RuntimeException
*/
public function write(Request $request, Response $response)
public function write(Request $request, Response $response): string
{
$key = $this->getCacheKey($request);
$storedEnv = $this->persistRequest($request);
@@ -197,7 +195,7 @@ class Store implements StoreInterface
if ($this->getPath($digest) !== $response->headers->get('X-Body-File')) {
throw new \RuntimeException('X-Body-File and X-Content-Digest do not match.');
}
// Everything seems ok, omit writing content to disk
// Everything seems ok, omit writing content to disk
} else {
$digest = $this->generateContentDigest($response);
$response->headers->set('X-Content-Digest', $digest);
@@ -242,17 +240,17 @@ class Store implements StoreInterface
/**
* Returns content digest for $response.
*
* @return string
*/
protected function generateContentDigest(Response $response)
protected function generateContentDigest(Response $response): string
{
return 'en'.hash('sha256', $response->getContent());
return 'en'.hash('xxh128', $response->getContent());
}
/**
* Invalidates all cache entries that match the request.
*
* @return void
*
* @throws \RuntimeException
*/
public function invalidate(Request $request)
@@ -324,7 +322,7 @@ class Store implements StoreInterface
*
* @return bool true if the URL exists with either HTTP or HTTPS scheme and has been purged, false otherwise
*/
public function purge(string $url)
public function purge(string $url): bool
{
$http = preg_replace('#^https:#', 'http:', $url);
$https = preg_replace('#^http:#', 'https:', $url);
@@ -419,6 +417,9 @@ class Store implements StoreInterface
return true;
}
/**
* @return string
*/
public function getPath(string $key)
{
return $this->root.\DIRECTORY_SEPARATOR.substr($key, 0, 2).\DIRECTORY_SEPARATOR.substr($key, 2, 2).\DIRECTORY_SEPARATOR.substr($key, 4, 2).\DIRECTORY_SEPARATOR.substr($key, 6);
@@ -433,10 +434,8 @@ class Store implements StoreInterface
* If the same URI can have more than one representation, based on some
* headers, use a Vary header to indicate them, and each representation will
* be stored independently under the same cache key.
*
* @return string
*/
protected function generateCacheKey(Request $request)
protected function generateCacheKey(Request $request): string
{
return 'md'.hash('sha256', $request->getUri());
}
@@ -475,15 +474,25 @@ class Store implements StoreInterface
/**
* Restores a Response from the HTTP headers and body.
*/
private function restoreResponse(array $headers, string $path = null): Response
private function restoreResponse(array $headers, string $path = null): ?Response
{
$status = $headers['X-Status'][0];
unset($headers['X-Status']);
$content = null;
if (null !== $path) {
$headers['X-Body-File'] = [$path];
unset($headers['x-body-file']);
if ($headers['X-Body-Eval'] ?? $headers['x-body-eval'] ?? false) {
$content = file_get_contents($path);
\assert(HttpCache::BODY_EVAL_BOUNDARY_LENGTH === 24);
if (48 > \strlen($content) || substr($content, -24) !== substr($content, 0, 24)) {
return null;
}
}
}
return new Response($path, $status, $headers);
return new Response($content, $status, $headers);
}
}