Skip to content

Commit 512bf78

Browse files
author
abluchet
committed
[Messenger] Allow sender tag name omission
1 parent 1f8e948 commit 512bf78

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

DependencyInjection/MessengerPass.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,11 @@ private function registerReceivers(ContainerBuilder $container)
157157
$receiverMapping = array();
158158
foreach ($container->findTaggedServiceIds('messenger.receiver') as $id => $tags) {
159159
foreach ($tags as $tag) {
160-
$receiverMapping[$tag['name'] ?? $id] = new Reference($id);
160+
$receiverMapping[$id] = new Reference($id);
161+
162+
if (isset($tag['name'])) {
163+
$receiverMapping[$tag['name']] = $receiverMapping[$id];
164+
}
161165
}
162166
}
163167

@@ -171,8 +175,8 @@ private function registerSenders(ContainerBuilder $container)
171175
foreach ($tags as $tag) {
172176
$senderLocatorMapping[$id] = new Reference($id);
173177

174-
if ($tag['name']) {
175-
$senderLocatorMapping[$tag['name']] = new Reference($id);
178+
if (isset($tag['name'])) {
179+
$senderLocatorMapping[$tag['name']] = $senderLocatorMapping[$id];
176180
}
177181
}
178182
}

Tests/DependencyInjection/MessengerPassTest.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,17 @@ public function testItRegistersReceivers()
9999

100100
(new MessengerPass())->process($container);
101101

102-
$this->assertEquals(array('amqp' => new Reference(AmqpReceiver::class)), $container->getDefinition('messenger.receiver_locator')->getArgument(0));
102+
$this->assertEquals(array('amqp' => new Reference(AmqpReceiver::class), AmqpReceiver::class => new Reference(AmqpReceiver::class)), $container->getDefinition('messenger.receiver_locator')->getArgument(0));
103+
}
104+
105+
public function testItRegistersReceiversWithoutTagName()
106+
{
107+
$container = $this->getContainerBuilder();
108+
$container->register(AmqpReceiver::class, AmqpReceiver::class)->addTag('messenger.receiver');
109+
110+
(new MessengerPass())->process($container);
111+
112+
$this->assertEquals(array(AmqpReceiver::class => new Reference(AmqpReceiver::class)), $container->getDefinition('messenger.receiver_locator')->getArgument(0));
103113
}
104114

105115
public function testItRegistersSenders()
@@ -112,6 +122,16 @@ public function testItRegistersSenders()
112122
$this->assertEquals(array('amqp' => new Reference(AmqpSender::class), AmqpSender::class => new Reference(AmqpSender::class)), $container->getDefinition('messenger.sender_locator')->getArgument(0));
113123
}
114124

125+
public function testItRegistersSenderWithoutTagName()
126+
{
127+
$container = $this->getContainerBuilder();
128+
$container->register(AmqpSender::class, AmqpSender::class)->addTag('messenger.sender');
129+
130+
(new MessengerPass())->process($container);
131+
132+
$this->assertEquals(array(AmqpSender::class => new Reference(AmqpSender::class)), $container->getDefinition('messenger.sender_locator')->getArgument(0));
133+
}
134+
115135
/**
116136
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
117137
* @expectedExceptionMessage Invalid handler service "Symfony\Component\Messenger\Tests\DependencyInjection\UndefinedMessageHandler": message class "Symfony\Component\Messenger\Tests\DependencyInjection\UndefinedMessage" used as argument type in method "Symfony\Component\Messenger\Tests\DependencyInjection\UndefinedMessageHandler::__invoke()" does not exist.

0 commit comments

Comments
 (0)