Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2e8cd93

Browse files
committed
Allow to configure or disable the message bus to use
1 parent 345eb75 commit 2e8cd93

25 files changed

+437
-12
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1811,6 +1811,9 @@ private function addNotifierSection(ArrayNodeDefinition $rootNode, callable $ena
18111811
->arrayNode('notifier')
18121812
->info('Notifier configuration')
18131813
->{$enableIfStandalone('symfony/notifier', Notifier::class)}()
1814+
->children()
1815+
->scalarNode('message_bus')->defaultNull()->info('The message bus to use. Defaults to the default bus if the Messenger component is installed.')->end()
1816+
->end()
18141817
->fixXmlConfig('chatter_transport')
18151818
->children()
18161819
->arrayNode('chatter_transports')

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2345,17 +2345,26 @@ private function registerNotifierConfiguration(array $config, ContainerBuilder $
23452345
$container->removeDefinition('notifier.channel.email');
23462346
}
23472347

2348+
$servicesWithBusArgument = ['texter', 'chatter', 'notifier.channel.chat', 'notifier.channel.email', 'notifier.channel.sms'];
2349+
if (false === $messageBus = $config['message_bus']) {
2350+
foreach ($servicesWithBusArgument as $serviceId) {
2351+
if ($container->hasDefinition($serviceId)) {
2352+
$container->getDefinition($serviceId)->replaceArgument(1, null);
2353+
}
2354+
}
2355+
} else {
2356+
foreach ($servicesWithBusArgument as $serviceId) {
2357+
if ($container->hasDefinition($serviceId)) {
2358+
$container->getDefinition($serviceId)->setArgument(0, null);
2359+
$container->getDefinition($serviceId)->replaceArgument(1, $messageBus ? new Reference($messageBus) : new Reference('messenger.default_bus', ContainerInterface::NULL_ON_INVALID_REFERENCE));
2360+
}
2361+
}
2362+
}
2363+
23482364
if ($this->messengerConfigEnabled) {
23492365
if ($config['notification_on_failed_messages']) {
23502366
$container->getDefinition('notifier.failed_message_listener')->addTag('kernel.event_subscriber');
23512367
}
2352-
2353-
// as we have a bus, the channels don't need the transports
2354-
$container->getDefinition('notifier.channel.chat')->setArgument(0, null);
2355-
if ($container->hasDefinition('notifier.channel.email')) {
2356-
$container->getDefinition('notifier.channel.email')->setArgument(0, null);
2357-
}
2358-
$container->getDefinition('notifier.channel.sms')->setArgument(0, null);
23592368
}
23602369

23612370
$container->getDefinition('notifier.channel_policy')->setArgument(0, $config['channel_policy']);

src/Symfony/Bundle/FrameworkBundle/Resources/config/notifier.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,24 @@
4646
->tag('notifier.channel', ['channel' => 'browser'])
4747

4848
->set('notifier.channel.chat', ChatChannel::class)
49-
->args([service('chatter.transports'), service('messenger.default_bus')->ignoreOnInvalid()])
49+
->args([
50+
service('chatter.transports'),
51+
abstract_arg('message bus'),
52+
])
5053
->tag('notifier.channel', ['channel' => 'chat'])
5154

5255
->set('notifier.channel.sms', SmsChannel::class)
53-
->args([service('texter.transports'), service('messenger.default_bus')->ignoreOnInvalid()])
56+
->args([
57+
service('texter.transports'),
58+
abstract_arg('message bus'),
59+
])
5460
->tag('notifier.channel', ['channel' => 'sms'])
5561

5662
->set('notifier.channel.email', EmailChannel::class)
57-
->args([service('mailer.transports'), service('messenger.default_bus')->ignoreOnInvalid()])
63+
->args([
64+
service('mailer.transports'),
65+
abstract_arg('message bus'),
66+
])
5867
->tag('notifier.channel', ['channel' => 'email'])
5968

6069
->set('notifier.monolog_handler', NotifierHandler::class)
@@ -66,7 +75,7 @@
6675
->set('chatter', Chatter::class)
6776
->args([
6877
service('chatter.transports'),
69-
service('messenger.default_bus')->ignoreOnInvalid(),
78+
abstract_arg('message bus'),
7079
service('event_dispatcher')->ignoreOnInvalid(),
7180
])
7281

@@ -86,7 +95,7 @@
8695
->set('texter', Texter::class)
8796
->args([
8897
service('texter.transports'),
89-
service('messenger.default_bus')->ignoreOnInvalid(),
98+
abstract_arg('message bus'),
9099
service('event_dispatcher')->ignoreOnInvalid(),
91100
])
92101

src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<xsd:element name="http-cache" type="http_cache" minOccurs="0" maxOccurs="1" />
3737
<xsd:element name="rate-limiter" type="rate_limiter" minOccurs="0" maxOccurs="1" />
3838
<xsd:element name="uid" type="uid" minOccurs="0" maxOccurs="1" />
39+
<xsd:element name="notifier" type="notifier" minOccurs="0" maxOccurs="1" />
3940
</xsd:choice>
4041

4142
<xsd:attribute name="http-method-override" type="xsd:boolean" />
@@ -727,4 +728,42 @@
727728
<xsd:enumeration value="1" />
728729
</xsd:restriction>
729730
</xsd:simpleType>
731+
732+
<xsd:complexType name="notifier">
733+
<xsd:sequence>
734+
<xsd:element name="chatter-transport" type="chatter-transport" minOccurs="0" maxOccurs="unbounded" />
735+
<xsd:element name="texter-transport" type="texter-transport" minOccurs="0" maxOccurs="unbounded" />
736+
<xsd:element name="channel-policy" type="channel-policy" minOccurs="0" maxOccurs="unbounded" />
737+
<xsd:element name="admin-recipients" type="admin-recipients" minOccurs="0" maxOccurs="1" />
738+
</xsd:sequence>
739+
<xsd:attribute name="enabled" type="xsd:boolean" />
740+
<xsd:attribute name="notification-on-failed-messages" type="xsd:boolean" />
741+
<xsd:attribute name="message-bus" type="xsd:string" />
742+
</xsd:complexType>
743+
744+
<xsd:complexType name="chatter-transport" mixed="true">
745+
<xsd:attribute name="name" type="xsd:string" use="required"/>
746+
</xsd:complexType>
747+
748+
<xsd:complexType name="texter-transport" mixed="true">
749+
<xsd:attribute name="name" type="xsd:string" use="required"/>
750+
</xsd:complexType>
751+
752+
<xsd:complexType name="channel-policy" mixed="true">
753+
<xsd:sequence>
754+
<xsd:element name="channel" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
755+
</xsd:sequence>
756+
<xsd:attribute name="name" type="xsd:string" use="required" />
757+
</xsd:complexType>
758+
759+
<xsd:complexType name="admin-recipients" mixed="true">
760+
<xsd:sequence>
761+
<xsd:element name="admin-recipient" type="admin-recipient" minOccurs="1" maxOccurs="unbounded" />
762+
</xsd:sequence>
763+
</xsd:complexType>
764+
765+
<xsd:complexType name="admin-recipient" mixed="true">
766+
<xsd:attribute name="email" type="xsd:string" use="required" />
767+
<xsd:attribute name="phone" type="xsd:string" />
768+
</xsd:complexType>
730769
</xsd:schema>

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ class_exists(SemaphoreStore::class) && SemaphoreStore::isSupported() ? 'semaphor
546546
],
547547
'notifier' => [
548548
'enabled' => !class_exists(FullStack::class) && class_exists(Notifier::class),
549+
'message_bus' => null,
549550
'chatter_transports' => [],
550551
'texter_transports' => [],
551552
'channel_policy' => [],
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\BarMessage;
4+
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\FooMessage;
5+
6+
$container->loadFromExtension('framework', [
7+
'messenger' => null,
8+
'mailer' => [
9+
'dsn' => 'smtp://example.com',
10+
],
11+
'notifier' => [
12+
'enabled' => true,
13+
'message_bus' => null,
14+
'notification_on_failed_messages' => true,
15+
'chatter_transports' => [
16+
'slack' => 'null'
17+
],
18+
'texter_transports' => [
19+
'twilio' => 'null'
20+
],
21+
'channel_policy' => [
22+
'low' => ['slack'],
23+
'high' => ['slack', 'twilio'],
24+
],
25+
'admin_recipients' => [
26+
['email' => '[email protected]', 'phone' => '+490815',],
27+
]
28+
],
29+
]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
$container->loadFromExtension('framework', [
4+
'mailer' => [
5+
'dsn' => 'smtp://example.com',
6+
],
7+
'notifier' => [
8+
'message_bus' => false,
9+
'chatter_transports' => [
10+
'test' => 'null'
11+
],
12+
'texter_transports' => [
13+
'test' => 'null'
14+
],
15+
],
16+
]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
$container->loadFromExtension('framework', [
4+
'mailer' => [
5+
'dsn' => 'smtp://example.com',
6+
],
7+
'notifier' => [
8+
'message_bus' => 'app.another_bus',
9+
'chatter_transports' => [
10+
'test' => 'null'
11+
],
12+
'texter_transports' => [
13+
'test' => 'null'
14+
],
15+
],
16+
]);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\BarMessage;
4+
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\FooMessage;
5+
6+
$container->loadFromExtension('framework', [
7+
'messenger' => null,
8+
'notifier' => [
9+
'enabled' => true,
10+
'message_bus' => null,
11+
'notification_on_failed_messages' => true,
12+
'chatter_transports' => [
13+
'slack' => 'null'
14+
],
15+
'texter_transports' => [
16+
'twilio' => 'null'
17+
],
18+
'channel_policy' => [
19+
'low' => ['slack'],
20+
'high' => ['slack', 'twilio'],
21+
],
22+
'admin_recipients' => [
23+
['email' => '[email protected]', 'phone' => '+490815',],
24+
]
25+
],
26+
]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\BarMessage;
4+
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\FooMessage;
5+
6+
$container->loadFromExtension('framework', [
7+
'mailer' => [
8+
'dsn' => 'smtp://example.com',
9+
],
10+
'notifier' => [
11+
'enabled' => true,
12+
'message_bus' => null,
13+
'notification_on_failed_messages' => true,
14+
'chatter_transports' => [
15+
'slack' => 'null'
16+
],
17+
'texter_transports' => [
18+
'twilio' => 'null'
19+
],
20+
'channel_policy' => [
21+
'low' => ['slack'],
22+
'high' => ['slack', 'twilio'],
23+
],
24+
'admin_recipients' => [
25+
['email' => '[email protected]', 'phone' => '+490815',],
26+
]
27+
],
28+
]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\BarMessage;
4+
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\FooMessage;
5+
6+
$container->loadFromExtension('framework', [
7+
'notifier' => [
8+
'enabled' => true,
9+
],
10+
]);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:framework="http://symfony.com/schema/dic/symfony"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
6+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
7+
8+
<framework:config>
9+
<framework:messenger enabled="true" />
10+
<framework:mailer dsn="smtp://example.com" />
11+
<framework:notifier enabled="true" message-bus="null" notification-on-failed-messages="true">
12+
<framework:chatter-transport name="slack">null</framework:chatter-transport>
13+
<framework:texter-transport name="twilio">null</framework:texter-transport>
14+
<framework:channel-policy name="low">slack</framework:channel-policy>
15+
<framework:channel-policy name="high">twilio</framework:channel-policy>
16+
<framework:admin-recipients>
17+
<framework:admin-recipient email="[email protected]" phone="+490815" />
18+
</framework:admin-recipients>
19+
</framework:notifier>
20+
</framework:config>
21+
</container>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:framework="http://symfony.com/schema/dic/symfony"
6+
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
7+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
8+
9+
<framework:config>
10+
<framework:mailer dsn="smtp://example.com" />
11+
<framework:notifier enabled="true" message-bus="false">
12+
<framework:chatter-transport name="test">null</framework:chatter-transport>
13+
<framework:texter-transport name="test">null</framework:texter-transport>
14+
</framework:notifier>
15+
</framework:config>
16+
</container>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:framework="http://symfony.com/schema/dic/symfony"
6+
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
7+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
8+
9+
<framework:config>
10+
<framework:mailer dsn="smtp://example.com" />
11+
<framework:notifier enabled="true" message-bus="app.another_bus">
12+
<framework:chatter-transport name="test">null</framework:chatter-transport>
13+
<framework:texter-transport name="test">null</framework:texter-transport>
14+
</framework:notifier>
15+
</framework:config>
16+
</container>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:framework="http://symfony.com/schema/dic/symfony"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
6+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
7+
8+
<framework:config>
9+
<framework:messenger enabled="true" />
10+
<framework:notifier enabled="true" message-bus="null" notification-on-failed-messages="true">
11+
<framework:chatter-transport name="slack">null</framework:chatter-transport>
12+
<framework:texter-transport name="twilio">null</framework:texter-transport>
13+
<framework:channel-policy name="low">slack</framework:channel-policy>
14+
<framework:channel-policy name="high">twilio</framework:channel-policy>
15+
<framework:admin-recipients>
16+
<framework:admin-recipient email="[email protected]" phone="+490815" />
17+
</framework:admin-recipients>
18+
</framework:notifier>
19+
</framework:config>
20+
</container>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:framework="http://symfony.com/schema/dic/symfony"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
6+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
7+
8+
<framework:config>
9+
<framework:mailer dsn="smtp://example.com" />
10+
<framework:notifier enabled="true" message-bus="null" notification-on-failed-messages="true">
11+
<framework:chatter-transport name="slack">null</framework:chatter-transport>
12+
<framework:texter-transport name="twilio">null</framework:texter-transport>
13+
<framework:channel-policy name="low">slack</framework:channel-policy>
14+
<framework:channel-policy name="high">twilio</framework:channel-policy>
15+
<framework:admin-recipients>
16+
<framework:admin-recipient email="[email protected]" phone="+490815" />
17+
</framework:admin-recipients>
18+
</framework:notifier>
19+
</framework:config>
20+
</container>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:framework="http://symfony.com/schema/dic/symfony"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
6+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
7+
8+
<framework:config>
9+
<framework:notifier enabled="true"></framework:notifier>
10+
</framework:config>
11+
</container>

0 commit comments

Comments
 (0)