8000 minor #27032 [Messenger][DX] Validate that the message exists to be a… · symfony/symfony@39c7c90 · GitHub
[go: up one dir, main page]

Skip to content

Commit 39c7c90

Browse files
committed
minor #27032 [Messenger][DX] Validate that the message exists to be able to configure its routing (sroze)
This PR was merged into the 4.1-dev branch. Discussion ---------- [Messenger][DX] Validate that the message exists to be able to configure its routing | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | ø | License | MIT | Doc PR | ø It attempted to me already: mispelling the message name and not understanding why it didn't work... An exception letting me know that the configured message does not exists will be 👌 Commits ------- 04d87ca Validate that the message exists to be able to configure its routing Uses an existing class in the tests... :) Only trigger the autoloading once
2 parents 3b363a8 + 04d87ca commit 39c7c90

File tree

6 files changed

+27
-6
lines changed

6 files changed

+27
-6
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,6 +1496,10 @@ private function registerMessengerConfiguration(array $config, ContainerBuilder
14961496

14971497
$messageToSenderIdsMapping = array();
14981498
foreach ($config['routing'] as $message => $messageConfiguration) {
1499+
if (!class_exists($message) && !interface_exists($message, false)) {
1500+
throw new LogicException(sprintf('Messenger routing configuration contains a mistake: message "%s" does not exist. It needs to match an existing class or interface.', $message));
1501+
}
1502+
14991503
$messageToSenderIdsMapping[$message] = $messageConfiguration['senders'];
15001504
}
15011505

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
<?php
22

3+
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\FooMessage;
4+
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\BarMessage;
5+
36
$container->loadFromExtension('framework', array(
47
'messenger' => array(
58
'routing' => array(
6-
'App\Bar' => array('sender.bar', 'sender.biz'),
7-
'App\Foo' => 'sender.foo',
9+
FooMessage::class => array('sender.bar', 'sender.biz'),
10+
BarMessage::class => 'sender.foo',
811
),
912
),
1013
));

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/messenger.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
<framework:config>
99
<framework:messenger>
10-
<framework:routing message-class="App\Bar">
10+
<framework:routing message-class="Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\FooMessage">
1111
<framework:sender service="sender.bar" />
1212
<framework:sender service="sender.biz" />
1313
</framework:routing>
14-
<framework:routing message-class="App\Foo">
14+
<framework:routing message-class="Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\BarMessage">
1515
<framework:sender service="sender.foo" />
1616
</framework:routing>
1717
</framework:messenger>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
framework:
22
messenger:
33
routing:
4-
'App\Bar': ['sender.bar', 'sender.biz']
5-
'App\Foo': 'sender.foo'
4+
'Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\FooMessage': ['sender.bar', 'sender.biz']
5+
'Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\BarMessage': 'sender.foo'
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger;
4+
5+
class BarMessage
6+
{
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger;
4+
5+
class FooMessage
6+
{
7+
}

0 commit comments

Comments
 (0)
0