cleaned up composer

This commit is contained in:
2026-02-18 20:17:19 -06:00
parent 3c94239da7
commit 3e153679bd
5952 changed files with 271417 additions and 203117 deletions

View File

@@ -25,20 +25,32 @@ use Symfony\Component\HttpFoundation\Response;
class Store implements StoreInterface
{
protected $root;
/** @var \SplObjectStorage<Request, string> */
private $keyCache;
private $locks;
/** @var array<string, resource> */
private $locks = [];
private $options;
/**
* Constructor.
*
* The available options are:
*
* * private_headers Set of response headers that should not be stored
* when a response is cached. (default: Set-Cookie)
*
* @throws \RuntimeException
*/
public function __construct(string $root)
public function __construct(string $root, array $options = [])
{
$this->root = $root;
if (!is_dir($this->root) && !@mkdir($this->root, 0777, true) && !is_dir($this->root)) {
throw new \RuntimeException(sprintf('Unable to create the store directory (%s).', $this->root));
}
$this->keyCache = new \SplObjectStorage();
$this->locks = [];
$this->options = array_merge([
'private_headers' => ['Set-Cookie'],
], $options);
}
/**
@@ -125,7 +137,7 @@ class Store implements StoreInterface
/**
* Locates a cached Response for the Request provided.
*
* @return Response|null A Response instance, or null if no cache entry was found
* @return Response|null
*/
public function lookup(Request $request)
{
@@ -166,7 +178,7 @@ 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 The key under which the response is stored
* @return string
*
* @throws \RuntimeException
*/
@@ -185,7 +197,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);
@@ -215,6 +227,10 @@ class Store implements StoreInterface
$headers = $this->persistResponse($response);
unset($headers['age']);
foreach ($this->options['private_headers'] as $h) {
unset($headers[strtolower($h)]);
}
array_unshift($entries, [$storedEnv, $headers]);
if (!$this->save($key, serialize($entries))) {
@@ -298,7 +314,7 @@ class Store implements StoreInterface
return [];
}
return unserialize($entries);
return unserialize($entries) ?: [];
}
/**
@@ -347,7 +363,7 @@ class Store implements StoreInterface
{
$path = $this->getPath($key);
return is_file($path) && false !== ($contents = file_get_contents($path)) ? $contents : null;
return is_file($path) && false !== ($contents = @file_get_contents($path)) ? $contents : null;
}
/**
@@ -418,7 +434,7 @@ class Store implements StoreInterface
* headers, use a Vary header to indicate them, and each representation will
* be stored independently under the same cache key.
*
* @return string A key for the given Request
* @return string
*/
protected function generateCacheKey(Request $request)
{
@@ -459,15 +475,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);
}
}