migration symfony 5 4 (#300)

* symfony 5.4 (diff dev)

* symfony 5.4 (working)

* symfony 5.4 (update autoload)

* symfony 5.4 (remove swiftmailer mailer implementation)

* symfony 5.4 (php doc and split Global accessor class)


### Impacted packages:

composer require php:">=7.2.5 <8.0.0" symfony/console:5.4.* symfony/dotenv:5.4.* symfony/framework-bundle:5.4.* symfony/twig-bundle:5.4.* symfony/yaml:5.4.* --update-with-dependencies

composer require symfony/stopwatch:5.4.* symfony/web-profiler-bundle:5.4.* --dev --update-with-dependencies
This commit is contained in:
bdalsass
2022-06-16 09:13:24 +02:00
committed by GitHub
parent abb13b70b9
commit 79da71ecf8
2178 changed files with 87439 additions and 59451 deletions

View File

@@ -17,6 +17,9 @@ use Symfony\Component\Cache\CacheItem;
use Symfony\Component\Cache\Exception\InvalidArgumentException;
use Symfony\Component\Cache\PruneableInterface;
use Symfony\Component\Cache\ResettableInterface;
use Symfony\Component\Cache\Traits\ContractsTrait;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\Service\ResetInterface;
/**
* Chains several adapters together.
@@ -26,17 +29,21 @@ use Symfony\Component\Cache\ResettableInterface;
*
* @author Kévin Dunglas <dunglas@gmail.com>
*/
class ChainAdapter implements AdapterInterface, PruneableInterface, ResettableInterface
class ChainAdapter implements AdapterInterface, CacheInterface, PruneableInterface, ResettableInterface
{
use ContractsTrait;
private $adapters = [];
private $adapterCount;
private $syncItem;
private $defaultLifetime;
private static $syncItem;
/**
* @param CacheItemPoolInterface[] $adapters The ordered list of adapters used to fetch cached items
* @param int $defaultLifetime The default lifetime of items propagated from lower adapters to upper ones
*/
public function __construct(array $adapters, $defaultLifetime = 0)
public function __construct(array $adapters, int $defaultLifetime = 0)
{
if (!$adapters) {
throw new InvalidArgumentException('At least one adapter must be specified.');
@@ -44,7 +51,7 @@ class ChainAdapter implements AdapterInterface, PruneableInterface, ResettableIn
foreach ($adapters as $adapter) {
if (!$adapter instanceof CacheItemPoolInterface) {
throw new InvalidArgumentException(sprintf('The class "%s" does not implement the "%s" interface.', \get_class($adapter), CacheItemPoolInterface::class));
throw new InvalidArgumentException(sprintf('The class "%s" does not implement the "%s" interface.', get_debug_type($adapter), CacheItemPoolInterface::class));
}
if (\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && $adapter instanceof ApcuAdapter && !filter_var(ini_get('apc.enable_cli'), \FILTER_VALIDATE_BOOLEAN)) {
continue; // skip putting APCu in the chain when the backend is disabled
@@ -57,13 +64,21 @@ class ChainAdapter implements AdapterInterface, PruneableInterface, ResettableIn
}
}
$this->adapterCount = \count($this->adapters);
$this->defaultLifetime = $defaultLifetime;
self::$syncItem ?? self::$syncItem = \Closure::bind(
static function ($sourceItem, $item, $defaultLifetime, $sourceMetadata = null) {
$sourceItem->isTaggable = false;
$sourceMetadata = $sourceMetadata ?? $sourceItem->metadata;
unset($sourceMetadata[CacheItem::METADATA_TAGS]);
$this->syncItem = \Closure::bind(
static function ($sourceItem, $item) use ($defaultLifetime) {
$item->value = $sourceItem->value;
$item->isHit = $sourceItem->isHit;
$item->metadata = $item->newMetadata = $sourceItem->metadata = $sourceMetadata;
if (0 < $defaultLifetime) {
if (isset($item->metadata[CacheItem::METADATA_EXPIRY])) {
$item->expiresAt(\DateTime::createFromFormat('U.u', sprintf('%.6F', $item->metadata[CacheItem::METADATA_EXPIRY])));
} elseif (0 < $defaultLifetime) {
$item->expiresAfter($defaultLifetime);
}
@@ -74,12 +89,40 @@ class ChainAdapter implements AdapterInterface, PruneableInterface, ResettableIn
);
}
/**
* {@inheritdoc}
*/
public function get(string $key, callable $callback, float $beta = null, array &$metadata = null)
{
$lastItem = null;
$i = 0;
$wrap = function (CacheItem $item = null) use ($key, $callback, $beta, &$wrap, &$i, &$lastItem, &$metadata) {
$adapter = $this->adapters[$i];
if (isset($this->adapters[++$i])) {
$callback = $wrap;
$beta = \INF === $beta ? \INF : 0;
}
if ($adapter instanceof CacheInterface) {
$value = $adapter->get($key, $callback, $beta, $metadata);
} else {
$value = $this->doGet($adapter, $key, $callback, $beta, $metadata);
}
if (null !== $item) {
(self::$syncItem)($lastItem = $lastItem ?? $item, $item, $this->defaultLifetime, $metadata);
}
return $value;
};
return $wrap();
}
/**
* {@inheritdoc}
*/
public function getItem($key)
{
$syncItem = $this->syncItem;
$syncItem = self::$syncItem;
$misses = [];
foreach ($this->adapters as $i => $adapter) {
@@ -87,7 +130,7 @@ class ChainAdapter implements AdapterInterface, PruneableInterface, ResettableIn
if ($item->isHit()) {
while (0 <= --$i) {
$this->adapters[$i]->save($syncItem($item, $misses[$i]));
$this->adapters[$i]->save($syncItem($item, $misses[$i], $this->defaultLifetime));
}
return $item;
@@ -107,12 +150,12 @@ class ChainAdapter implements AdapterInterface, PruneableInterface, ResettableIn
return $this->generateItems($this->adapters[0]->getItems($keys), 0);
}
private function generateItems($items, $adapterIndex)
private function generateItems(iterable $items, int $adapterIndex): \Generator
{
$missing = [];
$misses = [];
$nextAdapterIndex = $adapterIndex + 1;
$nextAdapter = isset($this->adapters[$nextAdapterIndex]) ? $this->adapters[$nextAdapterIndex] : null;
$nextAdapter = $this->adapters[$nextAdapterIndex] ?? null;
foreach ($items as $k => $item) {
if (!$nextAdapter || $item->isHit()) {
@@ -124,13 +167,13 @@ class ChainAdapter implements AdapterInterface, PruneableInterface, ResettableIn
}
if ($missing) {
$syncItem = $this->syncItem;
$syncItem = self::$syncItem;
$adapter = $this->adapters[$adapterIndex];
$items = $this->generateItems($nextAdapter->getItems($missing), $nextAdapterIndex);
foreach ($items as $k => $item) {
if ($item->isHit()) {
$adapter->save($syncItem($item, $misses[$k]));
$adapter->save($syncItem($item, $misses[$k], $this->defaultLifetime));
}
yield $k => $item;
@@ -140,6 +183,8 @@ class ChainAdapter implements AdapterInterface, PruneableInterface, ResettableIn
/**
* {@inheritdoc}
*
* @return bool
*/
public function hasItem($key)
{
@@ -154,14 +199,20 @@ class ChainAdapter implements AdapterInterface, PruneableInterface, ResettableIn
/**
* {@inheritdoc}
*
* @return bool
*/
public function clear()
public function clear(string $prefix = '')
{
$cleared = true;
$i = $this->adapterCount;
while ($i--) {
$cleared = $this->adapters[$i]->clear() && $cleared;
if ($this->adapters[$i] instanceof AdapterInterface) {
$cleared = $this->adapters[$i]->clear($prefix) && $cleared;
} else {
$cleared = $this->adapters[$i]->clear() && $cleared;
}
}
return $cleared;
@@ -169,6 +220,8 @@ class ChainAdapter implements AdapterInterface, PruneableInterface, ResettableIn
/**
* {@inheritdoc}
*
* @return bool
*/
public function deleteItem($key)
{
@@ -184,6 +237,8 @@ class ChainAdapter implements AdapterInterface, PruneableInterface, ResettableIn
/**
* {@inheritdoc}
*
* @return bool
*/
public function deleteItems(array $keys)
{
@@ -199,6 +254,8 @@ class ChainAdapter implements AdapterInterface, PruneableInterface, ResettableIn
/**
* {@inheritdoc}
*
* @return bool
*/
public function save(CacheItemInterface $item)
{
@@ -214,6 +271,8 @@ class ChainAdapter implements AdapterInterface, PruneableInterface, ResettableIn
/**
* {@inheritdoc}
*
* @return bool
*/
public function saveDeferred(CacheItemInterface $item)
{
@@ -229,6 +288,8 @@ class ChainAdapter implements AdapterInterface, PruneableInterface, ResettableIn
/**
* {@inheritdoc}
*
* @return bool
*/
public function commit()
{
@@ -264,7 +325,7 @@ class ChainAdapter implements AdapterInterface, PruneableInterface, ResettableIn
public function reset()
{
foreach ($this->adapters as $adapter) {
if ($adapter instanceof ResettableInterface) {
if ($adapter instanceof ResetInterface) {
$adapter->reset();
}
}