From 3cee1cac12e55aeff77ca2dfb7bab8f2f50134bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?THERAGE=20K=C3=A9vin?= Date: Mon, 25 Mar 2019 17:16:11 +0100 Subject: [PATCH] #30690 - Changing messenger bus id from 'message_bus' to 'messenger.default_bus' --- .../Bundle/FrameworkBundle/Controller/AbstractController.php | 1 + .../Bundle/FrameworkBundle/Controller/ControllerTrait.php | 4 ++-- .../DependencyInjection/FrameworkExtension.php | 3 ++- .../Tests/Controller/AbstractControllerTest.php | 1 + .../Tests/DependencyInjection/FrameworkExtensionTest.php | 4 ++++ 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php b/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php index a8b83f1e8b2fd..ac7ab231e01a9 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php +++ b/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php @@ -88,6 +88,7 @@ public static function getSubscribedServices() 'security.csrf.token_manager' => '?'.CsrfTokenManagerInterface::class, 'parameter_bag' => '?'.ContainerBagInterface::class, 'message_bus' => '?'.MessageBusInterface::class, + 'messenger.default_bus' => '?'.MessageBusInterface::class, ]; } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerTrait.php b/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerTrait.php index e32f7b6e25d0a..2f20678e318e3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerTrait.php +++ b/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerTrait.php @@ -403,12 +403,12 @@ protected function isCsrfTokenValid(string $id, ?string $token): bool */ protected function dispatchMessage($message): Envelope { - if (!$this->container->has('message_bus')) { + if (!$this->container->has('messenger.default_bus')) { $message = class_exists(Envelope::class) ? 'You need to define the "messenger.default_bus" configuration option.' : 'Try running "composer require symfony/messenger".'; throw new \LogicException('The message bus is not enabled in your application. '.$message); } - return $this->container->get('message_bus')->dispatch($message); + return $this->container->get('messenger.default_bus')->dispatch($message); } /** diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index fa505bbb0cf67..76ccb42ba2b83 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -1655,7 +1655,8 @@ private function registerMessengerConfiguration(array $config, ContainerBuilder $container->register($busId, MessageBus::class)->addArgument([])->addTag('messenger.bus'); if ($busId === $config['default_bus']) { - $container->setAlias('message_bus', $busId)->setPublic(true); + $container->setAlias('message_bus', $busId)->setPublic(true)->setDeprecated(true, 'The "%alias_id%" service is deprecated, use the "messenger.default_bus" service instead.'); + $container->setAlias('messenger.default_bus', $busId)->setPublic(true); $container->setAlias(MessageBusInterface::class, $busId); } else { $container->registerAliasForArgument($busId, MessageBusInterface::class); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/AbstractControllerTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/AbstractControllerTest.php index ddab6af2b6628..9c1e0b8d9a51d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/AbstractControllerTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/AbstractControllerTest.php @@ -43,6 +43,7 @@ public function testSubscribedServices() 'form.factory' => '?Symfony\\Component\\Form\\FormFactoryInterface', 'parameter_bag' => '?Symfony\\Component\\DependencyInjection\\ParameterBag\\ContainerBagInterface', 'message_bus' => '?Symfony\\Component\\Messenger\\MessageBusInterface', + 'messenger.default_bus' => '?Symfony\\Component\\Messenger\\MessageBusInterface', 'security.token_storage' => '?Symfony\\Component\\Security\\Core\\Authentication\\Token\\Storage\\TokenStorageInterface', 'security.csrf.token_manager' => '?Symfony\\Component\\Security\\Csrf\\CsrfTokenManagerInterface', ]; diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index ddd9d64286ff5..a5812e6e3cf40 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -648,6 +648,8 @@ public function testMessenger() $container = $this->createContainerFromFile('messenger'); $this->assertTrue($container->hasAlias('message_bus')); $this->assertTrue($container->getAlias('message_bus')->isPublic()); + $this->assertTrue($container->hasAlias('messenger.default_bus')); + $this->assertTrue($container->getAlias('messenger.default_bus')->isPublic()); $this->assertFalse($container->hasDefinition('messenger.transport.amqp.factory')); $this->assertTrue($container->hasDefinition('messenger.transport_factory')); $this->assertSame(TransportFactory::class, $container->getDefinition('messenger.transport_factory')->getClass()); @@ -750,6 +752,8 @@ public function testMessengerWithMultipleBuses() $this->assertTrue($container->hasAlias('message_bus')); $this->assertSame('messenger.bus.commands', (string) $container->getAlias('message_bus')); + $this->assertTrue($container->hasAlias('messenger.default_bus')); + $this->assertSame('messenger.bus.commands', (string) $container->getAlias('messenger.default_bus')); } /**