Updates to vendors etc

This commit is contained in:
Chris Hunt
2025-07-11 15:57:48 +01:00
parent d972cbcd0a
commit 8fb6438254
8043 changed files with 248005 additions and 189479 deletions

View File

@@ -12,12 +12,14 @@
namespace Symfony\Component\Cache\Adapter;
use Psr\Cache\CacheItemInterface;
use Psr\Clock\ClockInterface;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Symfony\Component\Cache\CacheItem;
use Symfony\Component\Cache\Exception\InvalidArgumentException;
use Symfony\Component\Cache\ResettableInterface;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\Cache\NamespacedPoolInterface;
/**
* An in-memory cache storage.
@@ -26,37 +28,35 @@ use Symfony\Contracts\Cache\CacheInterface;
*
* @author Nicolas Grekas <p@tchwork.com>
*/
class ArrayAdapter implements AdapterInterface, CacheInterface, LoggerAwareInterface, ResettableInterface
class ArrayAdapter implements AdapterInterface, CacheInterface, NamespacedPoolInterface, LoggerAwareInterface, ResettableInterface
{
use LoggerAwareTrait;
private bool $storeSerialized;
private array $values = [];
private array $tags = [];
private array $expiries = [];
private int $defaultLifetime;
private float $maxLifetime;
private int $maxItems;
private array $subPools = [];
private static \Closure $createCacheItem;
/**
* @param bool $storeSerialized Disabling serialization can lead to cache corruptions when storing mutable values but increases performance otherwise
*/
public function __construct(int $defaultLifetime = 0, bool $storeSerialized = true, float $maxLifetime = 0, int $maxItems = 0)
{
public function __construct(
private int $defaultLifetime = 0,
private bool $storeSerialized = true,
private float $maxLifetime = 0,
private int $maxItems = 0,
private ?ClockInterface $clock = null,
) {
if (0 > $maxLifetime) {
throw new InvalidArgumentException(sprintf('Argument $maxLifetime must be positive, %F passed.', $maxLifetime));
throw new InvalidArgumentException(\sprintf('Argument $maxLifetime must be positive, %F passed.', $maxLifetime));
}
if (0 > $maxItems) {
throw new InvalidArgumentException(sprintf('Argument $maxItems must be a positive integer, %d passed.', $maxItems));
throw new InvalidArgumentException(\sprintf('Argument $maxItems must be a positive integer, %d passed.', $maxItems));
}
$this->defaultLifetime = $defaultLifetime;
$this->storeSerialized = $storeSerialized;
$this->maxLifetime = $maxLifetime;
$this->maxItems = $maxItems;
self::$createCacheItem ??= \Closure::bind(
static function ($key, $value, $isHit, $tags) {
$item = new CacheItem();
@@ -98,7 +98,7 @@ class ArrayAdapter implements AdapterInterface, CacheInterface, LoggerAwareInter
public function hasItem(mixed $key): bool
{
if (\is_string($key) && isset($this->expiries[$key]) && $this->expiries[$key] > microtime(true)) {
if (\is_string($key) && isset($this->expiries[$key]) && $this->expiries[$key] > $this->getCurrentTime()) {
if ($this->maxItems) {
// Move the item last in the storage
$value = $this->values[$key];
@@ -133,7 +133,7 @@ class ArrayAdapter implements AdapterInterface, CacheInterface, LoggerAwareInter
{
\assert(self::validateKeys($keys));
return $this->generateItems($keys, microtime(true), self::$createCacheItem);
return $this->generateItems($keys, $this->getCurrentTime(), self::$createCacheItem);
}
public function deleteItem(mixed $key): bool
@@ -163,7 +163,7 @@ class ArrayAdapter implements AdapterInterface, CacheInterface, LoggerAwareInter
$value = $item["\0*\0value"];
$expiry = $item["\0*\0expiry"];
$now = microtime(true);
$now = $this->getCurrentTime();
if (null !== $expiry) {
if (!$expiry) {
@@ -220,7 +220,7 @@ class ArrayAdapter implements AdapterInterface, CacheInterface, LoggerAwareInter
public function clear(string $prefix = ''): bool
{
if ('' !== $prefix) {
$now = microtime(true);
$now = $this->getCurrentTime();
foreach ($this->values as $key => $value) {
if (!isset($this->expiries[$key]) || $this->expiries[$key] <= $now || str_starts_with($key, $prefix)) {
@@ -228,16 +228,38 @@ class ArrayAdapter implements AdapterInterface, CacheInterface, LoggerAwareInter
}
}
if ($this->values) {
return true;
}
return true;
}
$this->values = $this->tags = $this->expiries = [];
foreach ($this->subPools as $pool) {
$pool->clear();
}
$this->subPools = $this->values = $this->tags = $this->expiries = [];
return true;
}
public function withSubNamespace(string $namespace): static
{
CacheItem::validateKey($namespace);
$subPools = $this->subPools;
if (isset($subPools[$namespace])) {
return $subPools[$namespace];
}
$this->subPools = [];
$clone = clone $this;
$clone->clear();
$subPools[$namespace] = $clone;
$this->subPools = $subPools;
return $clone;
}
/**
* Returns all cached values, with cache miss as null.
*/
@@ -260,14 +282,18 @@ class ArrayAdapter implements AdapterInterface, CacheInterface, LoggerAwareInter
return $values;
}
/**
* @return void
*/
public function reset()
public function reset(): void
{
$this->clear();
}
public function __clone()
{
foreach ($this->subPools as $i => $pool) {
$this->subPools[$i] = clone $pool;
}
}
private function generateItems(array $keys, float $now, \Closure $f): \Generator
{
foreach ($keys as $i => $key) {
@@ -312,9 +338,11 @@ class ArrayAdapter implements AdapterInterface, CacheInterface, LoggerAwareInter
try {
$serialized = serialize($value);
} catch (\Exception $e) {
unset($this->values[$key], $this->tags[$key]);
if (!isset($this->expiries[$key])) {
unset($this->values[$key]);
}
$type = get_debug_type($value);
$message = sprintf('Failed to save key "{key}" of type %s: %s', $type, $e->getMessage());
$message = \sprintf('Failed to save key "{key}" of type %s: %s', $type, $e->getMessage());
CacheItem::log($this->logger, $message, ['key' => $key, 'exception' => $e, 'cache-adapter' => get_debug_type($this)]);
return null;
@@ -363,4 +391,9 @@ class ArrayAdapter implements AdapterInterface, CacheInterface, LoggerAwareInter
return true;
}
private function getCurrentTime(): float
{
return $this->clock?->now()->format('U.u') ?? microtime(true);
}
}