Content-Length: 325189 | pFad | http://github.com/symfony/symfony/commit/fcff4aed2e5b4589452d73b24df5db7dffa21416

72 [Messenger] Allow handler locator to be set · symfony/symfony@fcff4ae · GitHub
Skip to content

Commit fcff4ae

Browse files
committed
[Messenger] Allow handler locator to be set
The `HandleMessageMiddleware` has a dependency on a `HandlersLocatorInterface` but this gets registered by the messenger pass. As far as I can see there isn't a way for an application to provide it's own implementation. By checking if the service already exists before registering then we can allow applications to define their own
1 parent cd87bde commit fcff4ae

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/Symfony/Component/Messenger/DependencyInjection/MessengerPass.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,13 @@ private function registerHandlers(ContainerBuilder $container, array $busIds): v
165165
$container->addDefinitions($definitions);
166166

167167
foreach ($busIds as $bus) {
168-
$container->register($locatorId = $bus.'.messenger.handlers_locator', HandlersLocator::class)
169-
->setArgument(0, $handlersLocatorMappingByBus[$bus] ?? [])
170-
;
168+
$locatorId = $bus.'.messenger.handlers_locator';
169+
if (!$container->has($locatorId)) {
170+
$container->register($locatorId, HandlersLocator::class)
171+
->setArgument(0, $handlersLocatorMappingByBus[$bus] ?? [])
172+
;
173+
}
174+
171175
if ($container->has($handleMessageId = $bus.'.middleware.handle_message')) {
172176
$container->getDefinition($handleMessageId)
173177
->replaceArgument(0, new Reference($locatorId))

src/Symfony/Component/Messenger/Tests/DependencyInjection/MessengerPassTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,17 @@ public function testItRegistersTheDebugCommand()
809809
], $container->getDefinition('console.command.messenger_debug')->getArgument(0));
810810
}
811811

812+
public function testCanOverrideHandlersLocator()
813+
{
814+
$container = $this->getContainerBuilder($busId = 'message_bus');
815+
816+
$container->register($busId. '.messenger.handlers_locator', \stdClass::class);
817+
818+
(new MessengerPass())->process($container);
819+
820+
$this->assertSame(\stdClass::class, $container->getDefinition($busId. '.messenger.handlers_locator')->getClass());
821+
}
822+
812823
private function getContainerBuilder(string $busId = 'message_bus'): ContainerBuilder
813824
{
814825
$container = new ContainerBuilder();

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/symfony/symfony/commit/fcff4aed2e5b4589452d73b24df5db7dffa21416

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy