diff --git a/UPGRADE-5.4.md b/UPGRADE-5.4.md index 57d27502d6876..a2ce35807705d 100644 --- a/UPGRADE-5.4.md +++ b/UPGRADE-5.4.md @@ -37,6 +37,7 @@ FrameworkBundle * 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. + * In `framework.cache` configuration, using `cache.adapter.pdo` adapter with a Doctrine DBAL connection is deprecated, use `cache.adapter.doctrine_dbal` instead. HttpKernel ---------- diff --git a/UPGRADE-6.0.md b/UPGRADE-6.0.md index 7bcba1f6d0ddf..c5506acbea75e 100644 --- a/UPGRADE-6.0.md +++ b/UPGRADE-6.0.md @@ -109,6 +109,7 @@ FrameworkBundle * 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. + * In `framework.cache` configuration, using the `cache.adapter.pdo` with a Doctrine DBAL connection is no longer supported, use `cache.adapter.doctrine_dbal` instead. HttpFoundation -------------- diff --git a/src/Symfony/Bridge/Doctrine/SchemaListener/DoctrineDbalCacheAdapterSchemaSubscriber.php b/src/Symfony/Bridge/Doctrine/SchemaListener/DoctrineDbalCacheAdapterSchemaSubscriber.php index e61564807befd..bf9b793175f3f 100644 --- a/src/Symfony/Bridge/Doctrine/SchemaListener/DoctrineDbalCacheAdapterSchemaSubscriber.php +++ b/src/Symfony/Bridge/Doctrine/SchemaListener/DoctrineDbalCacheAdapterSchemaSubscriber.php @@ -14,7 +14,7 @@ use Doctrine\Common\EventSubscriber; use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs; use Doctrine\ORM\Tools\ToolEvents; -use Symfony\Component\Cache\Adapter\DoctrineSchemaConfiguratorInterface; +use Symfony\Component\Cache\Adapter\DoctrineDbalAdapter; /** * Automatically adds the cache table needed for the DoctrineDbalAdapter of @@ -27,7 +27,7 @@ final class DoctrineDbalCacheAdapterSchemaSubscriber implements EventSubscriber private $dbalAdapters; /** - * @param iterable $dbalAdapters + * @param iterable $dbalAdapters */ public function __construct(iterable $dbalAdapters) { diff --git a/src/Symfony/Bridge/Doctrine/SchemaListener/PdoCacheAdapterDoctrineSchemaSubscriber.php b/src/Symfony/Bridge/Doctrine/SchemaListener/PdoCacheAdapterDoctrineSchemaSubscriber.php index a46d4fa814cb4..98738ed58ec75 100644 --- a/src/Symfony/Bridge/Doctrine/SchemaListener/PdoCacheAdapterDoctrineSchemaSubscriber.php +++ b/src/Symfony/Bridge/Doctrine/SchemaListener/PdoCacheAdapterDoctrineSchemaSubscriber.php @@ -16,8 +16,6 @@ use Doctrine\ORM\Tools\ToolEvents; use Symfony\Component\Cache\Adapter\PdoAdapter; -trigger_deprecation('symfony/doctrine-bridge', '5.4', 'The "%s" class is deprecated, use "%s" instead.', PdoCacheAdapterDoctrineSchemaSubscriber::class, DoctrineDbalCacheAdapterSchemaSubscriber::class); - /** * Automatically adds the cache table needed for the PdoAdapter. * @@ -41,6 +39,10 @@ public function postGenerateSchema(GenerateSchemaEventArgs $event): void { $dbalConnection = $event->getEntityManager()->getConnection(); foreach ($this->pdoAdapters as $pdoAdapter) { + if (PdoAdapter::class !== \get_class($pdoAdapter)) { + trigger_deprecation('symfony/doctrine-bridge', '5.4', 'The "%s" class is deprecated, use "%s" instead.', self::class, DoctrineDbalCacheAdapterSchemaSubscriber::class); + } + $pdoAdapter->configureSchema($event->getSchema(), $dbalConnection); } } diff --git a/src/Symfony/Bridge/Doctrine/Tests/SchemaListener/DoctrineDbalCacheAdapterSchemaSubscriberTest.php b/src/Symfony/Bridge/Doctrine/Tests/SchemaListener/DoctrineDbalCacheAdapterSchemaSubscriberTest.php index 8f1afa99b1319..0a65b6e6bc720 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/SchemaListener/DoctrineDbalCacheAdapterSchemaSubscriberTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/SchemaListener/DoctrineDbalCacheAdapterSchemaSubscriberTest.php @@ -17,7 +17,7 @@ use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs; use PHPUnit\Framework\TestCase; use Symfony\Bridge\Doctrine\SchemaListener\DoctrineDbalCacheAdapterSchemaSubscriber; -use Symfony\Component\Cache\Adapter\DoctrineSchemaConfiguratorInterface; +use Symfony\Component\Cache\Adapter\DoctrineDbalAdapter; class DoctrineDbalCacheAdapterSchemaSubscriberTest extends TestCase { @@ -29,14 +29,15 @@ public function testPostGenerateSchema() $entityManager->expects($this->once()) ->method('getConnection') ->willReturn($dbalConnection); + $event = new GenerateSchemaEventArgs($entityManager, $schema); - $pdoAdapter = $this->createMock(DoctrineSchemaConfiguratorInterface::class); - $pdoAdapter->expects($this->once()) + $dbalAdapter = $this->createMock(DoctrineDbalAdapter::class); + $dbalAdapter->expects($this->once()) ->method('configureSchema') ->with($schema, $dbalConnection); - $subscriber = new DoctrineDbalCacheAdapterSchemaSubscriber([$pdoAdapter]); + $subscriber = new DoctrineDbalCacheAdapterSchemaSubscriber([$dbalAdapter]); $subscriber->postGenerateSchema($event); } } diff --git a/src/Symfony/Bridge/Doctrine/Tests/SchemaListener/PdoCacheAdapterDoctrineSchemaSubscriberTest.php b/src/Symfony/Bridge/Doctrine/Tests/SchemaListener/PdoCacheAdapterDoctrineSchemaSubscriberTest.php index 90b76328db9f9..26f42a6d48731 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/SchemaListener/PdoCacheAdapterDoctrineSchemaSubscriberTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/SchemaListener/PdoCacheAdapterDoctrineSchemaSubscriberTest.php @@ -17,6 +17,7 @@ use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs; use PHPUnit\Framework\TestCase; use Symfony\Bridge\Doctrine\SchemaListener\PdoCacheAdapterDoctrineSchemaSubscriber; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Symfony\Component\Cache\Adapter\PdoAdapter; /** @@ -24,20 +25,25 @@ */ class PdoCacheAdapterDoctrineSchemaSubscriberTest extends TestCase { + use ExpectDeprecationTrait; + public function testPostGenerateSchema() { $schema = new Schema(); $dbalConnection = $this->createMock(Connection::class); $entityManager = $this->createMock(EntityManagerInterface::class); - $entityManager->expects($this->once()) + $entityManager->expects($this->any()) ->method('getConnection') ->willReturn($dbalConnection); + $event = new GenerateSchemaEventArgs($entityManager, $schema); $pdoAdapter = $this->createMock(PdoAdapter::class); $pdoAdapter->expects($this->once()) ->method('configureSchema') - ->with($schema, $dbalConnection); + ->with($event->getSchema(), $event->getEntityManager()->getConnection()); + + $this->expectDeprecation('Since symfony/doctrine-bridge 5.4: The "Symfony\Bridge\Doctrine\SchemaListener\PdoCacheAdapterDoctrineSchemaSubscriber" class is deprecated, use "Symfony\Bridge\Doctrine\SchemaListener\DoctrineDbalCacheAdapterSchemaSubscriber" instead.'); $subscriber = new PdoCacheAdapterDoctrineSchemaSubscriber([$pdoAdapter]); $subscriber->postGenerateSchema($event); diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md index 21e565cefae1b..ea913ef985cc3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md @@ -21,6 +21,7 @@ CHANGELOG * Add support for `statusCode` default parameter when loading a template directly from route using the `Symfony\Bundle\FrameworkBundle\Controller\TemplateController` controller * Deprecate `translation:update` command, use `translation:extract` instead * Add `PhpStanExtractor` support for the PropertyInfo component + * Add `cache.adapter.doctrine_dbal` service to replace `cache.adapter.pdo` when a Doctrine DBAL connection is used. 5.3 --- diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 76955b05d566f..6b4b18ffebbef 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -1077,6 +1077,7 @@ private function addCacheSection(ArrayNodeDefinition $rootNode, callable $willBe ->scalarNode('default_psr6_provider')->end() ->scalarNode('default_redis_provider')->defaultValue('redis://localhost')->end() ->scalarNode('default_memcached_provider')->defaultValue('memcached://localhost')->end() + ->scalarNode('default_doctrine_dbal_provider')->defaultValue('database_connection')->end() ->scalarNode('default_pdo_provider')->defaultValue($willBeAvailable('doctrine/dbal', Connection::class) ? 'database_connection' : null)->end() ->arrayNode('pools') ->useAttributeAsKey('name') diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index c73b3a7c3463c..6f2f0ad09bc75 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -34,6 +34,8 @@ use Symfony\Component\Cache\Adapter\AdapterInterface; use Symfony\Component\Cache\Adapter\ArrayAdapter; use Symfony\Component\Cache\Adapter\ChainAdapter; +use Symfony\Component\Cache\Adapter\DoctrineAdapter; +use Symfony\Component\Cache\Adapter\DoctrineDbalAdapter; use Symfony\Component\Cache\Adapter\TagAwareAdapter; use Symfony\Component\Cache\DependencyInjection\CachePoolPass; use Symfony\Component\Cache\Marshaller\DefaultMarshaller; @@ -2159,6 +2161,14 @@ private function registerCacheConfiguration(array $config, ContainerBuilder $con $container->removeDefinition('cache.default_marshaller'); } + if (!class_exists(DoctrineAdapter::class)) { + $container->removeDefinition('cache.adapter.doctrine'); + } + + if (!class_exists(DoctrineDbalAdapter::class)) { + $container->removeDefinition('cache.adapter.doctrine_dbal'); + } + $version = new Parameter('container.build_id'); $container->getDefinition('cache.adapter.apcu')->replaceArgument(2, $version); $container->getDefinition('cache.adapter.system')->replaceArgument(2, $version); @@ -2171,7 +2181,7 @@ private function registerCacheConfiguration(array $config, ContainerBuilder $con // Inline any env vars referenced in the parameter $container->setParameter('cache.prefix.seed', $container->resolveEnvPlaceholders($container->getParameter('cache.prefix.seed'), true)); } - foreach (['doctrine', 'psr6', 'redis', 'memcached', 'pdo'] as $name) { + foreach (['doctrine', 'psr6', 'redis', 'memcached', 'doctrine_dbal', 'pdo'] as $name) { if (isset($config[$name = 'default_'.$name.'_provider'])) { $container->setAlias('cache.'.$name, new Alias(CachePoolPass::getServiceProvider($container, $config[$name]), false)); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/cache.php b/src/Symfony/Bundle/FrameworkBundle/Resources/config/cache.php index ef18c7cea2f4a..e333e5f54712c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/cache.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/cache.php @@ -17,6 +17,7 @@ use Symfony\Component\Cache\Adapter\ApcuAdapter; use Symfony\Component\Cache\Adapter\ArrayAdapter; use Symfony\Component\Cache\Adapter\DoctrineAdapter; +use Symfony\Component\Cache\Adapter\DoctrineDbalAdapter; use Symfony\Component\Cache\Adapter\FilesystemAdapter; use Symfony\Component\Cache\Adapter\MemcachedAdapter; use Symfony\Component\Cache\Adapter\PdoAdapter; @@ -93,10 +94,8 @@ ->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) + ->set('cache.adapter.doctrine', DoctrineAdapter::class) ->abstract() ->args([ abstract_arg('Doctrine provider service'), @@ -110,11 +109,8 @@ 'reset' => 'reset', ]) ->tag('monolog.logger', ['channel' => 'cache']) - ->deprecate('symfony/framework-bundle', '5.4', 'The abstract service "%service_id%" is deprecated.') - ; - } + ->deprecate('symfony/framework-bundle', '5.4', 'The "%service_id%" service inherits from "cache.adapter.doctrine" which is deprecated.') - $container->services() ->set('cache.adapter.filesystem', FilesystemAdapter::class) ->abstract() ->args([ @@ -188,6 +184,23 @@ ]) ->tag('monolog.logger', ['channel' => 'cache']) + ->set('cache.adapter.doctrine_dbal', DoctrineDbalAdapter::class) + ->abstract() + ->args([ + abstract_arg('DBAL connection service'), + '', // namespace + 0, // default lifetime + [], // table options + service('cache.default_marshaller')->ignoreOnInvalid(), + ]) + ->call('setLogger', [service('logger')->ignoreOnInvalid()]) + ->tag('cache.pool', [ + 'provider' => 'cache.default_doctrine_dbal_provider', + 'clearer' => 'cache.default_clearer', + 'reset' => 'reset', + ]) + ->tag('monolog.logger', ['channel' => 'cache']) + ->set('cache.adapter.pdo', PdoAdapter::class) ->abstract() ->args([ diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php index 8e3dc42faffb3..0b6ccbf3afab3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -504,6 +504,7 @@ protected static function getBundleDefaultConfig() 'directory' => '%kernel.cache_dir%/pools/app', 'default_redis_provider' => 'redis://localhost', 'default_memcached_provider' => 'memcached://localhost', + 'default_doctrine_dbal_provider' => 'database_connection', 'default_pdo_provider' => ContainerBuilder::willBeAvailable('doctrine/dbal', Connection::class, ['symfony/framework-bundle']) ? 'database_connection' : null, 'prefix_seed' => '_%kernel.project_dir%.%kernel.container_class%', ], diff --git a/src/Symfony/Component/Cache/Adapter/DoctrineDbalAdapter.php b/src/Symfony/Component/Cache/Adapter/DoctrineDbalAdapter.php index 4c1ce3a6cb737..73f0ea6bcc480 100644 --- a/src/Symfony/Component/Cache/Adapter/DoctrineDbalAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/DoctrineDbalAdapter.php @@ -23,7 +23,7 @@ use Symfony\Component\Cache\Marshaller\MarshallerInterface; use Symfony\Component\Cache\PruneableInterface; -final class DoctrineDbalAdapter extends AbstractAdapter implements PruneableInterface, DoctrineSchemaConfiguratorInterface +class DoctrineDbalAdapter extends AbstractAdapter implements PruneableInterface { protected $maxIdLength = 255; diff --git a/src/Symfony/Component/Cache/Adapter/DoctrineSchemaConfiguratorInterface.php b/src/Symfony/Component/Cache/Adapter/DoctrineSchemaConfiguratorInterface.php deleted file mode 100644 index 57812cabaf396..0000000000000 --- a/src/Symfony/Component/Cache/Adapter/DoctrineSchemaConfiguratorInterface.php +++ /dev/null @@ -1,26 +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\DBAL\Connection; -use Doctrine\DBAL\Schema\Schema; - -/** - * @internal - */ -interface DoctrineSchemaConfiguratorInterface -{ - /** - * Adds the Table to the Schema if the adapter uses this Connection. - */ - public function configureSchema(Schema $schema, Connection $forConnection): void; -} diff --git a/src/Symfony/Component/Cache/LockRegistry.php b/src/Symfony/Component/Cache/LockRegistry.php index 3fcb4081c3dda..910c11fae29c4 100644 --- a/src/Symfony/Component/Cache/LockRegistry.php +++ b/src/Symfony/Component/Cache/LockRegistry.php @@ -43,7 +43,6 @@ final class LockRegistry __DIR__.\DIRECTORY_SEPARATOR.'Adapter'.\DIRECTORY_SEPARATOR.'CouchbaseCollectionAdapter.php', __DIR__.\DIRECTORY_SEPARATOR.'Adapter'.\DIRECTORY_SEPARATOR.'DoctrineAdapter.php', __DIR__.\DIRECTORY_SEPARATOR.'Adapter'.\DIRECTORY_SEPARATOR.'DoctrineDbalAdapter.php', - __DIR__.\DIRECTORY_SEPARATOR.'Adapter'.\DIRECTORY_SEPARATOR.'DoctrineSchemaConfiguratorInterface.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',