From d4a0d83c58610be17a082a71219e062b2f914845 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Thu, 9 Sep 2021 16:50:01 +0200 Subject: [PATCH] [Cache] Remove support for Doctrine Cache --- .../Bundle/FrameworkBundle/CHANGELOG.md | 1 + .../Resources/config/cache.php | 22 ---- .../Fixtures/php/doctrine_cache.php | 13 --- .../Fixtures/xml/doctrine_cache.xml | 13 --- .../Fixtures/yml/doctrine_cache.yml | 7 -- .../FrameworkExtensionTest.php | 21 ---- .../Cache/Adapter/DoctrineAdapter.php | 110 ------------------ src/Symfony/Component/Cache/CHANGELOG.md | 2 +- src/Symfony/Component/Cache/LockRegistry.php | 1 - .../Tests/Adapter/DoctrineAdapterTest.php | 35 ------ .../CacheCollectorPassTest.php | 4 +- .../Cache/Tests/Fixtures/ArrayCache.php | 52 --------- src/Symfony/Component/Cache/composer.json | 1 - src/Symfony/Component/Cache/phpunit.xml.dist | 9 +- 14 files changed, 8 insertions(+), 283 deletions(-) delete mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/doctrine_cache.php delete mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/doctrine_cache.xml delete mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/doctrine_cache.yml delete mode 100644 src/Symfony/Component/Cache/Adapter/DoctrineAdapter.php delete mode 100644 src/Symfony/Component/Cache/Tests/Adapter/DoctrineAdapterTest.php delete mode 100644 src/Symfony/Component/Cache/Tests/Fixtures/ArrayCache.php diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md index 079831c53b105..882b04ebdc19e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md @@ -19,6 +19,7 @@ CHANGELOG * Remove all other values than "none", "php_array" and "file" for `framework.annotation.cache` * Register workflow services as private * Remove support for passing a `RouteCollectionBuilder` to `MicroKernelTrait::configureRoutes()`, type-hint `RoutingConfigurator` instead + * Remove the `cache.adapter.doctrine` service 5.4 --- diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/cache.php b/src/Symfony/Bundle/FrameworkBundle/Resources/config/cache.php index b36d18e280958..3f5d2a6434387 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/cache.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/cache.php @@ -16,7 +16,6 @@ use Symfony\Component\Cache\Adapter\AdapterInterface; use Symfony\Component\Cache\Adapter\ApcuAdapter; use Symfony\Component\Cache\Adapter\ArrayAdapter; -use Symfony\Component\Cache\Adapter\DoctrineAdapter; use Symfony\Component\Cache\Adapter\FilesystemAdapter; use Symfony\Component\Cache\Adapter\MemcachedAdapter; use Symfony\Component\Cache\Adapter\PdoAdapter; @@ -93,28 +92,7 @@ ->call('setLogger', [service('logger')->ignoreOnInvalid()]) ->tag('cache.pool', ['clearer' => 'cache.default_clearer', 'reset' => 'reset']) ->tag('monolog.logger', ['channel' => 'cache']) - ; - if (class_exists(DoctrineAdapter::class)) { - $container->services()->set('cache.adapter.doctrine', DoctrineAdapter::class) - ->abstract() - ->args([ - abstract_arg('Doctrine provider service'), - '', // namespace - 0, // default lifetime - ]) - ->call('setLogger', [service('logger')->ignoreOnInvalid()]) - ->tag('cache.pool', [ - 'provider' => 'cache.default_doctrine_provider', - 'clearer' => 'cache.default_clearer', - 'reset' => 'reset', - ]) - ->tag('monolog.logger', ['channel' => 'cache']) - ->deprecate('symfony/framework-bundle', '5.4', 'The abstract service "%service_id%" is deprecated.') - ; - } - - $container->services() ->set('cache.adapter.filesystem', FilesystemAdapter::class) ->abstract() ->args([ diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/doctrine_cache.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/doctrine_cache.php deleted file mode 100644 index f16fbbf2505f3..0000000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/doctrine_cache.php +++ /dev/null @@ -1,13 +0,0 @@ -loadFromExtension('framework', [ - 'cache' => [ - 'pools' => [ - 'cache.bar' => [ - 'adapter' => 'cache.adapter.doctrine', - 'default_lifetime' => 5, - 'provider' => 'app.doctrine_cache_provider', - ], - ], - ], -]); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/doctrine_cache.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/doctrine_cache.xml deleted file mode 100644 index 3a367716831bd..0000000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/doctrine_cache.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/doctrine_cache.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/doctrine_cache.yml deleted file mode 100644 index 4452cd69c847f..0000000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/doctrine_cache.yml +++ /dev/null @@ -1,7 +0,0 @@ -framework: - cache: - pools: - cache.bar: - adapter: cache.adapter.doctrine - default_lifetime: 5 - provider: app.doctrine_cache_provider diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 6924a692e5588..aa6cb0fe068a0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -24,7 +24,6 @@ use Symfony\Component\Cache\Adapter\ApcuAdapter; use Symfony\Component\Cache\Adapter\ArrayAdapter; use Symfony\Component\Cache\Adapter\ChainAdapter; -use Symfony\Component\Cache\Adapter\DoctrineAdapter; use Symfony\Component\Cache\Adapter\FilesystemAdapter; use Symfony\Component\Cache\Adapter\ProxyAdapter; use Symfony\Component\Cache\Adapter\RedisAdapter; @@ -1522,23 +1521,6 @@ public function testCachePoolServices() } } - /** - * @group legacy - */ - public function testDoctrineCache() - { - if (!class_exists(DoctrineAdapter::class)) { - self::markTestSkipped('This test requires symfony/cache 5.4 or lower.'); - } - - $container = $this->createContainerFromFile('doctrine_cache', [], true, false); - $container->setParameter('cache.prefix.seed', 'test'); - $container->addCompilerPass(new CachePoolPass()); - $container->compile(); - - $this->assertCachePoolServiceDefinitionIsCreated($container, 'cache.bar', 'cache.adapter.doctrine', 5); - } - public function testRedisTagAwareAdapter() { $container = $this->createContainerFromFile('cache', [], true); @@ -1973,9 +1955,6 @@ private function assertCachePoolServiceDefinitionIsCreated(ContainerBuilder $con case 'cache.adapter.apcu': $this->assertSame(ApcuAdapter::class, $parentDefinition->getClass()); break; - case 'cache.adapter.doctrine': - $this->assertSame(DoctrineAdapter::class, $parentDefinition->getClass()); - break; case 'cache.app': case 'cache.adapter.filesystem': $this->assertSame(FilesystemAdapter::class, $parentDefinition->getClass()); diff --git a/src/Symfony/Component/Cache/Adapter/DoctrineAdapter.php b/src/Symfony/Component/Cache/Adapter/DoctrineAdapter.php deleted file mode 100644 index 7077ab4228c47..0000000000000 --- a/src/Symfony/Component/Cache/Adapter/DoctrineAdapter.php +++ /dev/null @@ -1,110 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Cache\Adapter; - -use Doctrine\Common\Cache\CacheProvider; -use Doctrine\Common\Cache\Psr6\CacheAdapter; - -/** - * @author Nicolas Grekas - * - * @deprecated Since Symfony 5.4, use Doctrine\Common\Cache\Psr6\CacheAdapter instead - */ -class DoctrineAdapter extends AbstractAdapter -{ - private CacheProvider $provider; - - public function __construct(CacheProvider $provider, string $namespace = '', int $defaultLifetime = 0) - { - trigger_deprecation('symfony/cache', '5.4', '"%s" is deprecated, use "%s" instead.', __CLASS__, CacheAdapter::class); - - parent::__construct('', $defaultLifetime); - $this->provider = $provider; - $provider->setNamespace($namespace); - } - - /** - * {@inheritdoc} - */ - public function reset() - { - parent::reset(); - $this->provider->setNamespace($this->provider->getNamespace()); - } - - /** - * {@inheritdoc} - */ - protected function doFetch(array $ids): iterable - { - $unserializeCallbackHandler = ini_set('unserialize_callback_func', parent::class.'::handleUnserializeCallback'); - try { - return $this->provider->fetchMultiple($ids); - } catch (\Error $e) { - $trace = $e->getTrace(); - - if (isset($trace[0]['function']) && !isset($trace[0]['class'])) { - switch ($trace[0]['function']) { - case 'unserialize': - case 'apcu_fetch': - case 'apc_fetch': - throw new \ErrorException($e->getMessage(), $e->getCode(), \E_ERROR, $e->getFile(), $e->getLine()); - } - } - - throw $e; - } finally { - ini_set('unserialize_callback_func', $unserializeCallbackHandler); - } - } - - /** - * {@inheritdoc} - */ - protected function doHave(string $id): bool - { - return $this->provider->contains($id); - } - - /** - * {@inheritdoc} - */ - protected function doClear(string $namespace): bool - { - $namespace = $this->provider->getNamespace(); - - return isset($namespace[0]) - ? $this->provider->deleteAll() - : $this->provider->flushAll(); - } - - /** - * {@inheritdoc} - */ - protected function doDelete(array $ids): bool - { - $ok = true; - foreach ($ids as $id) { - $ok = $this->provider->delete($id) && $ok; - } - - return $ok; - } - - /** - * {@inheritdoc} - */ - protected function doSave(array $values, int $lifetime): array|bool - { - return $this->provider->saveMultiple($values, $lifetime); - } -} diff --git a/src/Symfony/Component/Cache/CHANGELOG.md b/src/Symfony/Component/Cache/CHANGELOG.md index c1b79c7143d36..eebe5329092ae 100644 --- a/src/Symfony/Component/Cache/CHANGELOG.md +++ b/src/Symfony/Component/Cache/CHANGELOG.md @@ -4,7 +4,7 @@ CHANGELOG 6.0 --- - * Remove `DoctrineProvider` + * Remove `DoctrineProvider` and `DoctrineAdapter` 5.4 --- diff --git a/src/Symfony/Component/Cache/LockRegistry.php b/src/Symfony/Component/Cache/LockRegistry.php index 9edfe3afe62ae..f7064f3d9538c 100644 --- a/src/Symfony/Component/Cache/LockRegistry.php +++ b/src/Symfony/Component/Cache/LockRegistry.php @@ -41,7 +41,6 @@ final class LockRegistry __DIR__.\DIRECTORY_SEPARATOR.'Adapter'.\DIRECTORY_SEPARATOR.'ChainAdapter.php', __DIR__.\DIRECTORY_SEPARATOR.'Adapter'.\DIRECTORY_SEPARATOR.'CouchbaseBucketAdapter.php', __DIR__.\DIRECTORY_SEPARATOR.'Adapter'.\DIRECTORY_SEPARATOR.'CouchbaseCollectionAdapter.php', - __DIR__.\DIRECTORY_SEPARATOR.'Adapter'.\DIRECTORY_SEPARATOR.'DoctrineAdapter.php', __DIR__.\DIRECTORY_SEPARATOR.'Adapter'.\DIRECTORY_SEPARATOR.'FilesystemAdapter.php', __DIR__.\DIRECTORY_SEPARATOR.'Adapter'.\DIRECTORY_SEPARATOR.'FilesystemTagAwareAdapter.php', __DIR__.\DIRECTORY_SEPARATOR.'Adapter'.\DIRECTORY_SEPARATOR.'MemcachedAdapter.php', diff --git a/src/Symfony/Component/Cache/Tests/Adapter/DoctrineAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/DoctrineAdapterTest.php deleted file mode 100644 index 1f501b0bd86c9..0000000000000 --- a/src/Symfony/Component/Cache/Tests/Adapter/DoctrineAdapterTest.php +++ /dev/null @@ -1,35 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Cache\Tests\Adapter; - -use Psr\Cache\CacheItemPoolInterface; -use Symfony\Component\Cache\Adapter\DoctrineAdapter; -use Symfony\Component\Cache\Tests\Fixtures\ArrayCache; - -/** - * @group legacy - * @group time-sensitive - */ -class DoctrineAdapterTest extends AdapterTestCase -{ - protected $skippedTests = [ - 'testDeferredSaveWithoutCommit' => 'Assumes a shared cache which ArrayCache is not.', - 'testSaveWithoutExpire' => 'Assumes a shared cache which ArrayCache is not.', - 'testNotUnserializable' => 'ArrayCache does not use serialize/unserialize', - 'testClearPrefix' => 'Doctrine cannot clear by prefix', - ]; - - public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterface - { - return new DoctrineAdapter(new ArrayCache($defaultLifetime), '', $defaultLifetime); - } -} diff --git a/src/Symfony/Component/Cache/Tests/DependencyInjection/CacheCollectorPassTest.php b/src/Symfony/Component/Cache/Tests/DependencyInjection/CacheCollectorPassTest.php index 8ea6950429faa..adaa7e4d17aeb 100644 --- a/src/Symfony/Component/Cache/Tests/DependencyInjection/CacheCollectorPassTest.php +++ b/src/Symfony/Component/Cache/Tests/DependencyInjection/CacheCollectorPassTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Cache\Tests\DependencyInjection; use PHPUnit\Framework\TestCase; +use Symfony\Component\Cache\Adapter\ArrayAdapter; use Symfony\Component\Cache\Adapter\FilesystemAdapter; use Symfony\Component\Cache\Adapter\PhpArrayAdapter; use Symfony\Component\Cache\Adapter\TagAwareAdapter; @@ -19,7 +20,6 @@ use Symfony\Component\Cache\Adapter\TraceableTagAwareAdapter; use Symfony\Component\Cache\DataCollector\CacheDataCollector; use Symfony\Component\Cache\DependencyInjection\CacheCollectorPass; -use Symfony\Component\Cache\Tests\Fixtures\ArrayCache; use Symfony\Component\DependencyInjection\Compiler\PassConfig; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; @@ -79,7 +79,7 @@ public function testProcessCacheObjectsAreDecorated() $collector = $container->register('data_collector.cache', CacheDataCollector::class); $container - ->register('cache.object', ArrayCache::class) + ->register('cache.object', ArrayAdapter::class) ->addTag('cache.pool', ['name' => 'cache.object']); $container diff --git a/src/Symfony/Component/Cache/Tests/Fixtures/ArrayCache.php b/src/Symfony/Component/Cache/Tests/Fixtures/ArrayCache.php deleted file mode 100644 index c869cc90eabd9..0000000000000 --- a/src/Symfony/Component/Cache/Tests/Fixtures/ArrayCache.php +++ /dev/null @@ -1,52 +0,0 @@ -doContains($id) ? $this->data[$id][0] : false; - } - - protected function doContains($id): bool - { - if (!isset($this->data[$id])) { - return false; - } - - $expiry = $this->data[$id][1]; - - return !$expiry || microtime(true) < $expiry || !$this->doDelete($id); - } - - protected function doSave($id, $data, $lifeTime = 0): bool - { - $this->data[$id] = [$data, $lifeTime ? microtime(true) + $lifeTime : false]; - - return true; - } - - protected function doDelete($id): bool - { - unset($this->data[$id]); - - return true; - } - - protected function doFlush(): bool - { - $this->data = []; - - return true; - } - - protected function doGetStats(): ?array - { - return null; - } -} diff --git a/src/Symfony/Component/Cache/composer.json b/src/Symfony/Component/Cache/composer.json index 97bf6430d96ad..4beed9dc1d9eb 100644 --- a/src/Symfony/Component/Cache/composer.json +++ b/src/Symfony/Component/Cache/composer.json @@ -30,7 +30,6 @@ }, "require-dev": { "cache/integration-tests": "dev-master", - "doctrine/cache": "^1.6|^2.0", "doctrine/dbal": "^2.10|^3.0", "predis/predis": "^1.1", "psr/simple-cache": "^1.0", diff --git a/src/Symfony/Component/Cache/phpunit.xml.dist b/src/Symfony/Component/Cache/phpunit.xml.dist index 9883d5369bd4e..b972421ba9aaf 100644 --- a/src/Symfony/Component/Cache/phpunit.xml.dist +++ b/src/Symfony/Component/Cache/phpunit.xml.dist @@ -40,11 +40,10 @@ Cache\IntegrationTests - Doctrine\Common\Cache - Symfony\Component\Cache - Symfony\Component\Cache\Tests\Fixtures - Symfony\Component\Cache\Tests\Traits - Symfony\Component\Cache\Traits + Symfony\Component\Cache + Symfony\Component\Cache\Tests\Fixtures + Symfony\Component\Cache\Tests\Traits + Symfony\Component\Cache\Traits