bug #26960 [Messenger] Allow sender tag name omission (soyuka)
This PR was merged into the 4.1-dev branch.
Discussion
----------
[Messenger] Allow sender tag name omission
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | na
| License | MIT
| Doc PR | na
Tag attributes are not mandatory.
Commits
-------
a4737915c8
[Messenger] Allow sender tag name omission
This commit is contained in:
commit
4af9003bd6
@ -157,7 +157,11 @@ class MessengerPass implements CompilerPassInterface
|
||||
$receiverMapping = array();
|
||||
foreach ($container->findTaggedServiceIds('messenger.receiver') as $id => $tags) {
|
||||
foreach ($tags as $tag) {
|
||||
$receiverMapping[$tag['name'] ?? $id] = new Reference($id);
|
||||
$receiverMapping[$id] = new Reference($id);
|
||||
|
||||
if (isset($tag['name'])) {
|
||||
$receiverMapping[$tag['name']] = $receiverMapping[$id];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -171,8 +175,8 @@ class MessengerPass implements CompilerPassInterface
|
||||
foreach ($tags as $tag) {
|
||||
$senderLocatorMapping[$id] = new Reference($id);
|
||||
|
||||
if ($tag['name']) {
|
||||
$senderLocatorMapping[$tag['name']] = new Reference($id);
|
||||
if (isset($tag['name'])) {
|
||||
$senderLocatorMapping[$tag['name']] = $senderLocatorMapping[$id];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -99,7 +99,17 @@ class MessengerPassTest extends TestCase
|
||||
|
||||
(new MessengerPass())->process($container);
|
||||
|
||||
$this->assertEquals(array('amqp' => new Reference(AmqpReceiver::class)), $container->getDefinition('messenger.receiver_locator')->getArgument(0));
|
||||
$this->assertEquals(array('amqp' => new Reference(AmqpReceiver::class), AmqpReceiver::class => new Reference(AmqpReceiver::class)), $container->getDefinition('messenger.receiver_locator')->getArgument(0));
|
||||
}
|
||||
|
||||
public function testItRegistersReceiversWithoutTagName()
|
||||
{
|
||||
$container = $this->getContainerBuilder();
|
||||
$container->register(AmqpReceiver::class, AmqpReceiver::class)->addTag('messenger.receiver');
|
||||
|
||||
(new MessengerPass())->process($container);
|
||||
|
||||
$this->assertEquals(array(AmqpReceiver::class => new Reference(AmqpReceiver::class)), $container->getDefinition('messenger.receiver_locator')->getArgument(0));
|
||||
}
|
||||
|
||||
public function testItRegistersSenders()
|
||||
@ -112,6 +122,16 @@ class MessengerPassTest extends TestCase
|
||||
$this->assertEquals(array('amqp' => new Reference(AmqpSender::class), AmqpSender::class => new Reference(AmqpSender::class)), $container->getDefinition('messenger.sender_locator')->getArgument(0));
|
||||
}
|
||||
|
||||
public function testItRegistersSenderWithoutTagName()
|
||||
{
|
||||
$container = $this->getContainerBuilder();
|
||||
$container->register(AmqpSender::class, AmqpSender::class)->addTag('messenger.sender');
|
||||
|
||||
(new MessengerPass())->process($container);
|
||||
|
||||
$this->assertEquals(array(AmqpSender::class => new Reference(AmqpSender::class)), $container->getDefinition('messenger.sender_locator')->getArgument(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
|
||||
* @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.
|
||||
|
Reference in New Issue
Block a user