From c435315c3d55a1b5845329e090ec814c1cfc8e03 Mon Sep 17 00:00:00 2001 From: Allison Guilhem Date: Fri, 10 Mar 2023 14:16:02 +0100 Subject: [PATCH] [DoctrineBundle] feat: doctrine schema subscribers as listeners --- .../Compiler/CacheSchemaSubscriberPass.php | 3 +++ DependencyInjection/DoctrineExtension.php | 24 ++++++++++++++----- DoctrineBundle.php | 2 +- Resources/config/messenger.xml | 6 +++++ Resources/config/orm.xml | 18 ++++++++++---- Tests/CacheSchemaSubscriberTest.php | 11 ++++++--- ...st.php => LockStoreSchemaListenerTest.php} | 8 +++---- 7 files changed, 54 insertions(+), 18 deletions(-) rename Tests/{LockStoreSchemaSubscriberTest.php => LockStoreSchemaListenerTest.php} (92%) diff --git a/DependencyInjection/Compiler/CacheSchemaSubscriberPass.php b/DependencyInjection/Compiler/CacheSchemaSubscriberPass.php index 7f519031c..ee813d1b1 100644 --- a/DependencyInjection/Compiler/CacheSchemaSubscriberPass.php +++ b/DependencyInjection/Compiler/CacheSchemaSubscriberPass.php @@ -20,8 +20,11 @@ class CacheSchemaSubscriberPass implements CompilerPassInterface */ public function process(ContainerBuilder $container) { + // deprecated in Symfony 6.3 $this->injectAdapters($container, 'doctrine.orm.listeners.doctrine_dbal_cache_adapter_schema_subscriber', DoctrineDbalAdapter::class); + $this->injectAdapters($container, 'doctrine.orm.listeners.doctrine_dbal_cache_adapter_schema_listener', DoctrineDbalAdapter::class); + // available in Symfony 5.1 and up to Symfony 5.4 (deprecated) $this->injectAdapters($container, 'doctrine.orm.listeners.pdo_cache_adapter_doctrine_schema_subscriber', PdoAdapter::class); } diff --git a/DependencyInjection/DoctrineExtension.php b/DependencyInjection/DoctrineExtension.php index 064f410d4..20a2f3092 100644 --- a/DependencyInjection/DoctrineExtension.php +++ b/DependencyInjection/DoctrineExtension.php @@ -36,9 +36,12 @@ use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator; use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator; use Symfony\Bridge\Doctrine\PropertyInfo\DoctrineExtractor; -use Symfony\Bridge\Doctrine\SchemaListener\LockStoreSchemaSubscriber; +use Symfony\Bridge\Doctrine\SchemaListener\DoctrineDbalCacheAdapterSchemaListener; +use Symfony\Bridge\Doctrine\SchemaListener\LockStoreSchemaListener; +use Symfony\Bridge\Doctrine\SchemaListener\MessengerTransportDoctrineSchemaListener; use Symfony\Bridge\Doctrine\SchemaListener\PdoCacheAdapterDoctrineSchemaSubscriber; -use Symfony\Bridge\Doctrine\SchemaListener\PdoSessionHandlerSchemaSubscriber; +use Symfony\Bridge\Doctrine\SchemaListener\PdoSessionHandlerSchemaListener; +use Symfony\Bridge\Doctrine\SchemaListener\RememberMeTokenProviderDoctrineSchemaListener; use Symfony\Bridge\Doctrine\Validator\DoctrineLoader; use Symfony\Component\Cache\Adapter\ArrayAdapter; use Symfony\Component\Cache\Adapter\PhpArrayAdapter; @@ -394,18 +397,24 @@ protected function ormLoad(array $config, ContainerBuilder $container) $container->removeAlias('doctrine.orm.metadata.annotation_reader'); } + // available in Symfony 6.3 + $container->removeDefinition('doctrine.orm.listeners.doctrine_dbal_cache_adapter_schema_' . (class_exists(DoctrineDbalCacheAdapterSchemaListener::class) ? 'subscriber' : 'listener')); + + // available in Symfony 6.3 + $container->removeDefinition('doctrine.orm.listeners.doctrine_token_provider_schema_' . (class_exists(RememberMeTokenProviderDoctrineSchemaListener::class) ? 'subscriber' : 'listener')); + // available in Symfony 5.1 and up to Symfony 5.4 (deprecated) if (! class_exists(PdoCacheAdapterDoctrineSchemaSubscriber::class)) { $container->removeDefinition('doctrine.orm.listeners.pdo_cache_adapter_doctrine_schema_subscriber'); } - if (! class_exists(PdoSessionHandlerSchemaSubscriber::class)) { - $container->removeDefinition('doctrine.orm.listeners.pdo_session_handler_schema_subscriber'); + if (! class_exists(PdoSessionHandlerSchemaListener::class)) { + $container->removeDefinition('doctrine.orm.listeners.pdo_session_handler_schema_listener'); } // available in Symfony 6.3 and higher - if (! class_exists(LockStoreSchemaSubscriber::class)) { - $container->removeDefinition('doctrine.orm.listeners.lock_store_schema_subscriber'); + if (! class_exists(LockStoreSchemaListener::class)) { + $container->removeDefinition('doctrine.orm.listeners.lock_store_schema_listener'); } if (! class_exists(UlidGenerator::class)) { @@ -1063,6 +1072,9 @@ private function loadMessengerServices(ContainerBuilder $container): void $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $loader->load('messenger.xml'); + // available in Symfony 6.3 + $container->removeDefinition('doctrine.orm.messenger.doctrine_schema_' . (class_exists(MessengerTransportDoctrineSchemaListener::class) ? 'subscriber' : 'listener')); + /** * The Doctrine transport component (symfony/doctrine-messenger) is optional. * Remove service definition, if it is not available diff --git a/DoctrineBundle.php b/DoctrineBundle.php index cfa7419bb..5496d09a2 100644 --- a/DoctrineBundle.php +++ b/DoctrineBundle.php @@ -50,7 +50,7 @@ public function process(ContainerBuilder $container): void return; } - $container->removeDefinition('doctrine.orm.listeners.pdo_session_handler_schema_subscriber'); + $container->removeDefinition('doctrine.orm.listeners.pdo_session_handler_schema_listener'); } }, PassConfig::TYPE_BEFORE_OPTIMIZATION); diff --git a/Resources/config/messenger.xml b/Resources/config/messenger.xml index a4bd5f07a..6cb7ec5a3 100644 --- a/Resources/config/messenger.xml +++ b/Resources/config/messenger.xml @@ -52,8 +52,14 @@ + The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future. + + + + + diff --git a/Resources/config/orm.xml b/Resources/config/orm.xml index b0d7ce0f4..2492d5f94 100644 --- a/Resources/config/orm.xml +++ b/Resources/config/orm.xml @@ -133,24 +133,34 @@ + The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future. + + + + + The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future. - + + + + + - + - + - + diff --git a/Tests/CacheSchemaSubscriberTest.php b/Tests/CacheSchemaSubscriberTest.php index 8fdc12221..aa90f892d 100644 --- a/Tests/CacheSchemaSubscriberTest.php +++ b/Tests/CacheSchemaSubscriberTest.php @@ -6,7 +6,7 @@ use Doctrine\Bundle\DoctrineBundle\DependencyInjection\DoctrineExtension; use Doctrine\ORM\EntityManagerInterface; use Generator; -use Symfony\Bridge\Doctrine\SchemaListener\DoctrineDbalCacheAdapterSchemaSubscriber; +use Symfony\Bridge\Doctrine\SchemaListener\DoctrineDbalCacheAdapterSchemaListener; use Symfony\Bridge\Doctrine\SchemaListener\PdoCacheAdapterDoctrineSchemaSubscriber; use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension; use Symfony\Component\DependencyInjection\Alias; @@ -76,7 +76,7 @@ public function testSchemaSubscriberWiring(string $adapterId, string $subscriber ], $container); $container->setAlias('test_subscriber_alias', new Alias($subscriberId, true)); - // prevent my_cache_apapter from inlining + // prevent my_cache_adapter from inlining $container->register('uses_my_cache_adapter', 'stdClass') ->addArgument(new Reference('my_cache_adapter')) ->setPublic(true); @@ -90,7 +90,12 @@ public function testSchemaSubscriberWiring(string $adapterId, string $subscriber public function getSchemaSubscribers(): Generator { - yield ['cache.adapter.doctrine_dbal', 'doctrine.orm.listeners.doctrine_dbal_cache_adapter_schema_subscriber', DoctrineDbalCacheAdapterSchemaSubscriber::class]; + /** + * available in Symfony 6.3 + * + * @psalm-suppress UndefinedClass + */ + yield ['cache.adapter.doctrine_dbal', 'doctrine.orm.listeners.doctrine_dbal_cache_adapter_schema_listener', DoctrineDbalCacheAdapterSchemaListener::class]; /** * available in Symfony 5.1 and up to Symfony 5.4 (deprecated) diff --git a/Tests/LockStoreSchemaSubscriberTest.php b/Tests/LockStoreSchemaListenerTest.php similarity index 92% rename from Tests/LockStoreSchemaSubscriberTest.php rename to Tests/LockStoreSchemaListenerTest.php index 59cff5eed..8e026e26d 100644 --- a/Tests/LockStoreSchemaSubscriberTest.php +++ b/Tests/LockStoreSchemaListenerTest.php @@ -4,7 +4,7 @@ use Doctrine\Bundle\DoctrineBundle\DependencyInjection\DoctrineExtension; use Doctrine\ORM\EntityManagerInterface; -use Symfony\Bridge\Doctrine\SchemaListener\LockStoreSchemaSubscriber; +use Symfony\Bridge\Doctrine\SchemaListener\LockStoreSchemaListener; use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension; use Symfony\Component\DependencyInjection\Alias; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -14,7 +14,7 @@ use function interface_exists; use function sys_get_temp_dir; -class LockStoreSchemaSubscriberTest extends TestCase +class LockStoreSchemaListenerTest extends TestCase { /** * @param array $config @@ -24,7 +24,7 @@ class LockStoreSchemaSubscriberTest extends TestCase */ public function testLockStoreSchemaSubscriberWiring(array $config, int $expectedCount): void { - if (! class_exists(LockStoreSchemaSubscriber::class)) { + if (! class_exists(LockStoreSchemaListener::class)) { self::markTestSkipped('symfony/doctrine-bridge version not supported'); } @@ -59,7 +59,7 @@ public function testLockStoreSchemaSubscriberWiring(array $config, int $expected $container->setAlias( 'test_subscriber_lock_alias', - new Alias('doctrine.orm.listeners.lock_store_schema_subscriber', true), + new Alias('doctrine.orm.listeners.lock_store_schema_listener', true), ); $container->compile();