From 6eb3f5a35be77852bf47d4319a0dbd7ff8bf524b Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 13 Jun 2025 23:29:58 +0200 Subject: [PATCH 1/3] fix compatibility with Relay 0.11 --- Traits/Relay/BgsaveTrait.php | 36 ++++++++++++++++++++++++++++++++++++ Traits/RelayProxy.php | 7 ++----- 2 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 Traits/Relay/BgsaveTrait.php diff --git a/Traits/Relay/BgsaveTrait.php b/Traits/Relay/BgsaveTrait.php new file mode 100644 index 0000000..367f82f --- /dev/null +++ b/Traits/Relay/BgsaveTrait.php @@ -0,0 +1,36 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Cache\Traits\Relay; + +if (version_compare(phpversion('relay'), '0.11', '>=')) { + /** + * @internal + */ + trait BgsaveTrait + { + public function bgsave($arg = null): \Relay\Relay|bool + { + return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->bgsave(...\func_get_args()); + } + } +} else { + /** + * @internal + */ + trait BgsaveTrait + { + public function bgsave($schedule = false): \Relay\Relay|bool + { + return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->bgsave(...\func_get_args()); + } + } +} diff --git a/Traits/RelayProxy.php b/Traits/RelayProxy.php index e86c210..620eb1b 100644 --- a/Traits/RelayProxy.php +++ b/Traits/RelayProxy.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Cache\Traits; +use Symfony\Component\Cache\Traits\Relay\BgsaveTrait; use Symfony\Component\Cache\Traits\Relay\CopyTrait; use Symfony\Component\Cache\Traits\Relay\GeosearchTrait; use Symfony\Component\Cache\Traits\Relay\GetrangeTrait; @@ -32,6 +33,7 @@ class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectState::class); */ class RelayProxy extends \Relay\Relay implements ResetInterface, LazyObjectInterface { + use BgsaveTrait; use CopyTrait; use GeosearchTrait; use GetrangeTrait; @@ -341,11 +343,6 @@ public function lcs($key1, $key2, $options = null): mixed return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->lcs(...\func_get_args()); } - public function bgsave($schedule = false): \Relay\Relay|bool - { - return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->bgsave(...\func_get_args()); - } - public function save(): \Relay\Relay|bool { return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->save(...\func_get_args()); From f42f71198dc928ed1d1b642a909e7e0f986408bf Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Thu, 19 Jun 2025 14:15:09 +0200 Subject: [PATCH 2/3] [Cache] Fix assert parameter order --- Tests/DataCollector/CacheDataCollectorTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/DataCollector/CacheDataCollectorTest.php b/Tests/DataCollector/CacheDataCollectorTest.php index cea761f..e2cebc7 100644 --- a/Tests/DataCollector/CacheDataCollectorTest.php +++ b/Tests/DataCollector/CacheDataCollectorTest.php @@ -120,9 +120,9 @@ public function testLateCollect() $stats = $collector->getStatistics(); $this->assertGreaterThan(0, $stats[self::INSTANCE_NAME]['time']); - $this->assertEquals($stats[self::INSTANCE_NAME]['hits'], 0, 'hits'); - $this->assertEquals($stats[self::INSTANCE_NAME]['misses'], 1, 'misses'); - $this->assertEquals($stats[self::INSTANCE_NAME]['calls'], 1, 'calls'); + $this->assertEquals(0, $stats[self::INSTANCE_NAME]['hits'], 'hits'); + $this->assertEquals(1, $stats[self::INSTANCE_NAME]['misses'], 'misses'); + $this->assertEquals(1, $stats[self::INSTANCE_NAME]['calls'], 'calls'); $this->assertInstanceOf(Data::class, $collector->getCalls()); } From c88690befb8d4a85dc321fb78d677507f5eb141b Mon Sep 17 00:00:00 2001 From: Indra Gunawan Date: Fri, 30 May 2025 15:52:26 +0800 Subject: [PATCH 3/3] [Cache] Fix using a `ChainAdapter` as an adapter for a pool --- DependencyInjection/CachePoolPass.php | 4 +++- Tests/DependencyInjection/CachePoolPassTest.php | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/DependencyInjection/CachePoolPass.php b/DependencyInjection/CachePoolPass.php index 90c0890..80b8a94 100644 --- a/DependencyInjection/CachePoolPass.php +++ b/DependencyInjection/CachePoolPass.php @@ -58,9 +58,11 @@ public function process(ContainerBuilder $container) continue; } $class = $adapter->getClass(); + $providers = $adapter->getArguments(); while ($adapter instanceof ChildDefinition) { $adapter = $container->findDefinition($adapter->getParent()); $class = $class ?: $adapter->getClass(); + $providers += $adapter->getArguments(); if ($t = $adapter->getTag('cache.pool')) { $tags[0] += $t[0]; } @@ -90,7 +92,7 @@ public function process(ContainerBuilder $container) if (ChainAdapter::class === $class) { $adapters = []; - foreach ($adapter->getArgument(0) as $provider => $adapter) { + foreach ($providers['index_0'] ?? $providers[0] as $provider => $adapter) { if ($adapter instanceof ChildDefinition) { $chainedPool = $adapter; } else { diff --git a/Tests/DependencyInjection/CachePoolPassTest.php b/Tests/DependencyInjection/CachePoolPassTest.php index eaf5929..a50792f 100644 --- a/Tests/DependencyInjection/CachePoolPassTest.php +++ b/Tests/DependencyInjection/CachePoolPassTest.php @@ -209,7 +209,8 @@ public function testChainAdapterPool() $container->register('cache.adapter.apcu', ApcuAdapter::class) ->setArguments([null, 0, null]) ->addTag('cache.pool'); - $container->register('cache.chain', ChainAdapter::class) + $container->register('cache.adapter.chain', ChainAdapter::class); + $container->setDefinition('cache.chain', new ChildDefinition('cache.adapter.chain')) ->addArgument(['cache.adapter.array', 'cache.adapter.apcu']) ->addTag('cache.pool'); $container->setDefinition('cache.app', new ChildDefinition('cache.chain')) @@ -224,7 +225,7 @@ public function testChainAdapterPool() $this->assertSame('cache.chain', $appCachePool->getParent()); $chainCachePool = $container->getDefinition('cache.chain'); - $this->assertNotInstanceOf(ChildDefinition::class, $chainCachePool); + $this->assertInstanceOf(ChildDefinition::class, $chainCachePool); $this->assertCount(2, $chainCachePool->getArgument(0)); $this->assertInstanceOf(ChildDefinition::class, $chainCachePool->getArgument(0)[0]); $this->assertSame('cache.adapter.array', $chainCachePool->getArgument(0)[0]->getParent());