diff --git a/UPGRADE-5.4.md b/UPGRADE-5.4.md index b3ec3bc0aa686..d87a3205cf4b3 100644 --- a/UPGRADE-5.4.md +++ b/UPGRADE-5.4.md @@ -45,6 +45,7 @@ Messenger * Deprecate not setting the `delete_after_ack` config option (or DSN parameter) using the Redis transport, its default value will change to `true` in 6.0 + * Deprecate not setting the `reset_on_message` config option, its default value will change to `true` in 6.0 SecurityBundle -------------- diff --git a/UPGRADE-6.0.md b/UPGRADE-6.0.md index eaf8456bbd2e1..a9c3df35a388f 100644 --- a/UPGRADE-6.0.md +++ b/UPGRADE-6.0.md @@ -157,6 +157,7 @@ Messenger * Removed the `prefetch_count` parameter in the AMQP bridge. * Removed the use of TLS option for Redis Bridge, use `rediss://127.0.0.1` instead of `redis://127.0.0.1?tls=1` * The `delete_after_ack` config option of the Redis transport now defaults to `true` + * The `reset_on_message` config option now defaults to `true` Mime ---- diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 30ebe5fdb7270..cd4d45ff4c015 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -242,7 +242,7 @@ public function load(array $configs, ContainerBuilder $container) $container->registerAliasForArgument('parameter_bag', PsrContainerInterface::class); - if (class_exists(Application::class)) { + if ($this->hasConsole()) { $loader->load('console.php'); if (!class_exists(BaseXliffLintCommand::class)) { @@ -599,6 +599,11 @@ public function getConfiguration(array $config, ContainerBuilder $container) return new Configuration($container->getParameter('kernel.debug')); } + protected function hasConsole(): bool + { + return class_exists(Application::class); + } + private function registerFormConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader) { $loader->load('form.php'); @@ -2081,7 +2086,9 @@ private function registerMessengerConfiguration(array $config, ContainerBuilder throw new LogicException('The "framework.messenger.reset_on_message" configuration option can be set to "true" only. To prevent services resetting after each message you can set the "--no-reset" option in "messenger:consume" command.'); } - if (null === $config['reset_on_message']) { + if (!$container->hasDefinition('console.command.messenger_consume_messages')) { + $container->removeDefinition('messenger.listener.reset_services'); + } elseif (null === $config['reset_on_message']) { trigger_deprecation('symfony/framework-bundle', '5.4', 'Not setting the "framework.messenger.reset_on_message" configuration option is deprecated, it will default to "true" in version 6.0.'); $container->getDefinition('console.command.messenger_consume_messages')->replaceArgument(5, null); diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/messenger.php b/src/Symfony/Bundle/FrameworkBundle/Resources/config/messenger.php index bca022f903680..68c97b7da84bc 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/messenger.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/messenger.php @@ -201,7 +201,6 @@ ->set('messenger.listener.reset_services', ResetServicesListener::class) ->args([ service('services_resetter'), - abstract_arg('receivers names'), ]) ->set('messenger.routable_message_bus', RoutableMessageBus::class) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index d425a3aa55bcc..fee9e7f8f9f0e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -746,6 +746,25 @@ public function testMessenger() $this->assertSame('messenger.listener.reset_services', (string) $container->getDefinition('console.command.messenger_consume_messages')->getArgument(5)); } + public function testMessengerWithoutConsole() + { + $extension = $this->createPartialMock(FrameworkExtension::class, ['hasConsole', 'getAlias']); + $extension->method('hasConsole')->willReturn(false); + $extension->method('getAlias')->willReturn((new FrameworkExtension())->getAlias()); + + $container = $this->createContainerFromFile('messenger', [], true, false, $extension); + $container->compile(); + + $this->assertFalse($container->hasDefinition('console.command.messenger_consume_messages')); + $this->assertTrue($container->hasAlias('messenger.default_bus')); + $this->assertTrue($container->getAlias('messenger.default_bus')->isPublic()); + $this->assertTrue($container->hasDefinition('messenger.transport.amqp.factory')); + $this->assertTrue($container->hasDefinition('messenger.transport.redis.factory')); + $this->assertTrue($container->hasDefinition('messenger.transport_factory')); + $this->assertSame(TransportFactory::class, $container->getDefinition('messenger.transport_factory')->getClass()); + $this->assertFalse($container->hasDefinition('messenger.listener.reset_services')); + } + public function testMessengerMultipleFailureTransports() { $container = $this->createContainerFromFile('messenger_multiple_failure_transports'); @@ -1960,14 +1979,14 @@ protected function createContainer(array $data = []) ], $data))); } - protected function createContainerFromFile($file, $data = [], $resetCompilerPasses = true, $compile = true) + protected function createContainerFromFile($file, $data = [], $resetCompilerPasses = true, $compile = true, FrameworkExtension $extension = null) { $cacheKey = md5(static::class.$file.serialize($data)); if ($compile && isset(self::$containerCache[$cacheKey])) { return self::$containerCache[$cacheKey]; } $container = $this->createContainer($data); - $container->registerExtension(new FrameworkExtension()); + $container->registerExtension($extension ?: new FrameworkExtension()); $this->loadFromFile($container, $file); if ($resetCompilerPasses) { diff --git a/src/Symfony/Component/Messenger/CHANGELOG.md b/src/Symfony/Component/Messenger/CHANGELOG.md index 529ba46305d5d..86c1d97234b00 100644 --- a/src/Symfony/Component/Messenger/CHANGELOG.md +++ b/src/Symfony/Component/Messenger/CHANGELOG.md @@ -8,6 +8,7 @@ CHANGELOG * Add support for resetting container services after each messenger message. * Added `WorkerMetadata` class which allows you to access the configuration details of a worker, like `queueNames` and `transportNames` it consumes from. * New method `getMetadata()` was added to `Worker` class which returns the `WorkerMetadata` object. + * Deprecate not setting the `reset_on_message` config option, its default value will change to `true` in 6.0 5.3 ---