From 2dea081dcfc8784a0cd08dbbcccfb90e48ba6f1a Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 31 Oct 2018 17:58:27 +0100 Subject: [PATCH] Remove legacy workarounds for Messenger integration --- .../Compiler/MessengerPass.php | 27 -------- DependencyInjection/DoctrineExtension.php | 9 +-- DoctrineBundle.php | 2 - Resources/config/messenger.xml | 11 +-- .../Compiler/MessengerPassTest.php | 69 ------------------- 5 files changed, 6 insertions(+), 112 deletions(-) delete mode 100644 DependencyInjection/Compiler/MessengerPass.php delete mode 100644 Tests/DependencyInjection/Compiler/MessengerPassTest.php diff --git a/DependencyInjection/Compiler/MessengerPass.php b/DependencyInjection/Compiler/MessengerPass.php deleted file mode 100644 index 1ee532430..000000000 --- a/DependencyInjection/Compiler/MessengerPass.php +++ /dev/null @@ -1,27 +0,0 @@ -hasAlias('message_bus') && is_subclass_of($container->findDefinition('message_bus')->getClass(), MessageBusInterface::class)) { - return; - } - - // Remove wired services if the Messenger component actually isn't enabled: - $container->removeDefinition('doctrine.orm.messenger.middleware_factory.transaction'); - $container->removeDefinition('messenger.middleware.doctrine_transaction_middleware'); - } -} diff --git a/DependencyInjection/DoctrineExtension.php b/DependencyInjection/DoctrineExtension.php index f352722a0..f6385a54b 100644 --- a/DependencyInjection/DoctrineExtension.php +++ b/DependencyInjection/DoctrineExtension.php @@ -10,7 +10,7 @@ use LogicException; use Symfony\Bridge\Doctrine\DependencyInjection\AbstractDoctrineExtension; use Symfony\Bridge\Doctrine\Form\Type\DoctrineType; -use Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddlewareFactory; +use Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddleware; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\Alias; use Symfony\Component\DependencyInjection\ChildDefinition; @@ -390,13 +390,10 @@ protected function ormLoad(array $config, ContainerBuilder $container) ->addTag(ServiceRepositoryCompilerPass::REPOSITORY_SERVICE_TAG); } - // If the Messenger component is installed and the doctrine transaction middleware factory is available, wire it: - if (interface_exists(MessageBusInterface::class) && class_exists(DoctrineTransactionMiddlewareFactory::class)) { + // If the Messenger component is installed and the doctrine transaction middleware is available, wire it: + if (interface_exists(MessageBusInterface::class) && class_exists(DoctrineTransactionMiddleware::class)) { $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $loader->load('messenger.xml'); - - $container->getDefinition('messenger.middleware.doctrine_transaction_middleware') - ->replaceArgument(0, $config['default_entity_manager']); } /* diff --git a/DoctrineBundle.php b/DoctrineBundle.php index 95ccf47f7..d1f84ae5d 100644 --- a/DoctrineBundle.php +++ b/DoctrineBundle.php @@ -3,7 +3,6 @@ namespace Doctrine\Bundle\DoctrineBundle; use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\EntityListenerPass; -use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\MessengerPass; use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\ServiceRepositoryCompilerPass; use Doctrine\Common\Util\ClassUtils; use Doctrine\ORM\EntityManager; @@ -40,7 +39,6 @@ public function build(ContainerBuilder $container) $container->addCompilerPass(new DoctrineValidationPass('orm')); $container->addCompilerPass(new EntityListenerPass()); $container->addCompilerPass(new ServiceRepositoryCompilerPass()); - $container->addCompilerPass(new MessengerPass()); } /** diff --git a/Resources/config/messenger.xml b/Resources/config/messenger.xml index c44d38599..269e42d9f 100644 --- a/Resources/config/messenger.xml +++ b/Resources/config/messenger.xml @@ -4,17 +4,12 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - - - - - - - + + diff --git a/Tests/DependencyInjection/Compiler/MessengerPassTest.php b/Tests/DependencyInjection/Compiler/MessengerPassTest.php deleted file mode 100644 index 31b2114d4..000000000 --- a/Tests/DependencyInjection/Compiler/MessengerPassTest.php +++ /dev/null @@ -1,69 +0,0 @@ -markTestSkipped('Symfony Messenger component is not installed'); - } - - public function testRemovesDefinitionsWhenMessengerComponentIsDisabled() - { - $pass = new MessengerPass(); - $container = new ContainerBuilder(); - $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../../../Resources/config')); - $loader->load('messenger.xml'); - - $pass->process($container); - - $this->assertFalse($container->hasDefinition('doctrine.orm.messenger.middleware_factory.transaction')); - $this->assertFalse($container->hasDefinition('messenger.middleware.doctrine_transaction_middleware')); - } - - public function testRemoveDefinitionsWhenHasAliasButNotMessengerComponent() - { - $pass = new MessengerPass(); - $container = new ContainerBuilder(); - $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../../../Resources/config')); - $loader->load('messenger.xml'); - - $container->register('some_other_bus', stdClass::class); - $container->setAlias('message_bus', 'some_other_bus'); - - $pass->process($container); - - $this->assertFalse($container->hasDefinition('doctrine.orm.messenger.middleware_factory.transaction')); - $this->assertFalse($container->hasDefinition('messenger.middleware.doctrine_transaction_middleware')); - } - - public function testDoesNotRemoveDefinitionsWhenMessengerComponentIsEnabled() - { - $pass = new MessengerPass(); - $container = new ContainerBuilder(); - $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../../../Resources/config')); - $loader->load('messenger.xml'); - - $container->register('messenger.bus.default', MessageBus::class); - $container->setAlias('message_bus', 'messenger.bus.default'); - - $pass->process($container); - - $this->assertTrue($container->hasDefinition('doctrine.orm.messenger.middleware_factory.transaction')); - $this->assertTrue($container->hasDefinition('messenger.middleware.doctrine_transaction_middleware')); - } -}