diff --git a/UPGRADE-5.4.md b/UPGRADE-5.4.md index c33ca71796a06..b3ec3bc0aa686 100644 --- a/UPGRADE-5.4.md +++ b/UPGRADE-5.4.md @@ -4,7 +4,7 @@ UPGRADE FROM 5.3 to 5.4 Cache ----- - * Deprecate `DoctrineProvider` because this class has been added to the `doctrine/cache` package + * Deprecate `DoctrineProvider` and `DoctrineAdapter` because these classes have been added to the `doctrine/cache` package Console ------- @@ -28,6 +28,7 @@ FrameworkBundle * Deprecate the `AdapterInterface` autowiring alias, use `CacheItemPoolInterface` instead * Deprecate the public `profiler` service to private * Deprecate `get()`, `has()`, `getDoctrine()`, and `dispatchMessage()` in `AbstractController`, use method/constructor injection instead + * Deprecate the `cache.adapter.doctrine` service: The Doctrine Cache library is deprecated. Either switch to Symfony Cache or use the PSR-6 adapters provided by Doctrine Cache. HttpKernel ---------- diff --git a/UPGRADE-6.0.md b/UPGRADE-6.0.md index 5962274d9d43b..eaf8456bbd2e1 100644 --- a/UPGRADE-6.0.md +++ b/UPGRADE-6.0.md @@ -14,7 +14,7 @@ DoctrineBridge Cache ----- - * Remove `DoctrineProvider` because it has been added to the `doctrine/cache` package + * Remove `DoctrineProvider` and `DoctrineAdapter` because these classes have been added to the `doctrine/cache` package Config ------ @@ -104,6 +104,7 @@ FrameworkBundle * Remove option `--output-format` of the `translation:update` command, use e.g. `--output-format=xlf20` instead * Remove the `AdapterInterface` autowiring alias, use `CacheItemPoolInterface` instead * Remove `get()`, `has()`, `getDoctrine()`, and `dispatchMessage()` in `AbstractController`, use method/constructor injection instead + * Deprecate the `cache.adapter.doctrine` service: The Doctrine Cache library is deprecated. Either switch to Symfony Cache or use the PSR-6 adapters provided by Doctrine Cache. HttpFoundation -------------- diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md index cccfb1174e212..4d89c1bffc00c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md @@ -9,6 +9,7 @@ CHANGELOG * Deprecate the public `profiler` service to private * Deprecate `get()`, `has()`, `getDoctrine()`, and `dispatchMessage()` in `AbstractController`, use method/constructor injection instead * Add `MicroKernelTrait::getBundlesPath` method to get bundles config path + * Deprecate the `cache.adapter.doctrine` service 5.3 --- diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/cache.php b/src/Symfony/Bundle/FrameworkBundle/Resources/config/cache.php index eabda934aeea8..a15885003c70a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/cache.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/cache.php @@ -93,8 +93,10 @@ ->call('setLogger', [service('logger')->ignoreOnInvalid()]) ->tag('cache.pool', ['clearer' => 'cache.default_clearer', 'reset' => 'reset']) ->tag('monolog.logger', ['channel' => 'cache']) + ; - ->set('cache.adapter.doctrine', DoctrineAdapter::class) + if (class_exists(DoctrineAdapter::class)) { + $container->services()->set('cache.adapter.doctrine', DoctrineAdapter::class) ->abstract() ->args([ abstract_arg('Doctrine provider service'), @@ -108,7 +110,11 @@ '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/cache.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/cache.php index a060c13f930cd..9ca04b6c63bf9 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/cache.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/cache.php @@ -7,11 +7,6 @@ 'adapter' => 'cache.adapter.apcu', 'default_lifetime' => 30, ], - 'cache.bar' => [ - 'adapter' => 'cache.adapter.doctrine', - 'default_lifetime' => 5, - 'provider' => 'app.doctrine_cache_provider', - ], 'cache.baz' => [ 'adapter' => 'cache.adapter.filesystem', 'default_lifetime' => 7, 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 new file mode 100644 index 0000000000000..f16fbbf2505f3 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/doctrine_cache.php @@ -0,0 +1,13 @@ +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/cache.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/cache.xml index 2750715f6b7e2..7c75178c8cf0a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/cache.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/cache.xml @@ -8,7 +8,6 @@ - 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 new file mode 100644 index 0000000000000..3a367716831bd --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/doctrine_cache.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/cache.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/cache.yml index 8c9e10b82ee6c..c89c027f5aecf 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/cache.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/cache.yml @@ -4,10 +4,6 @@ framework: cache.foo: adapter: cache.adapter.apcu default_lifetime: 30 - cache.bar: - adapter: cache.adapter.doctrine - default_lifetime: 5 - provider: app.doctrine_cache_provider cache.baz: adapter: cache.adapter.filesystem default_lifetime: 7 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 new file mode 100644 index 0000000000000..4452cd69c847f --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/doctrine_cache.yml @@ -0,0 +1,7 @@ +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 e20736f7b9d69..3315664ec80ba 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -1519,7 +1519,6 @@ public function testCachePoolServices() $container->compile(); $this->assertCachePoolServiceDefinitionIsCreated($container, 'cache.foo', 'cache.adapter.apcu', 30); - $this->assertCachePoolServiceDefinitionIsCreated($container, 'cache.bar', 'cache.adapter.doctrine', 5); $this->assertCachePoolServiceDefinitionIsCreated($container, 'cache.baz', 'cache.adapter.filesystem', 7); $this->assertCachePoolServiceDefinitionIsCreated($container, 'cache.foobar', 'cache.adapter.psr6', 10); $this->assertCachePoolServiceDefinitionIsCreated($container, 'cache.def', 'cache.app', 'PT11S'); @@ -1561,6 +1560,23 @@ 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); diff --git a/src/Symfony/Component/Cache/Adapter/DoctrineAdapter.php b/src/Symfony/Component/Cache/Adapter/DoctrineAdapter.php index dc70ea69738bf..efa30c842e427 100644 --- a/src/Symfony/Component/Cache/Adapter/DoctrineAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/DoctrineAdapter.php @@ -12,9 +12,12 @@ 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 { @@ -22,6 +25,8 @@ class DoctrineAdapter extends AbstractAdapter 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); diff --git a/src/Symfony/Component/Cache/CHANGELOG.md b/src/Symfony/Component/Cache/CHANGELOG.md index 787942f85c115..4c77b45d4660b 100644 --- a/src/Symfony/Component/Cache/CHANGELOG.md +++ b/src/Symfony/Component/Cache/CHANGELOG.md @@ -5,7 +5,7 @@ CHANGELOG --- * Make `LockRegistry` use semaphores when possible - * Deprecate `DoctrineProvider` because this class has been added to the `doctrine/cache` package + * Deprecate `DoctrineProvider` and `DoctrineAdapter` because these classes have been added to the `doctrine/cache` package 5.3 --- diff --git a/src/Symfony/Component/Cache/Tests/Adapter/DoctrineAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/DoctrineAdapterTest.php index 310aa4387a490..1f501b0bd86c9 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/DoctrineAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/DoctrineAdapterTest.php @@ -16,6 +16,7 @@ use Symfony\Component\Cache\Tests\Fixtures\ArrayCache; /** + * @group legacy * @group time-sensitive */ class DoctrineAdapterTest extends AdapterTestCase