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

Skip to content

Commit 3e800b6

Browse files
committed
Allow to configure or disable the message bus to use
1 parent 0eebd9e commit 3e800b6

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
@@ -2352,17 +2352,26 @@ private function registerNotifierConfiguration(array $config, ContainerBuilder $
23522352
$container->removeDefinition('notifier.channel.email');
23532353
}
23542354

2355+
$servicesWithBusArgument = ['texter', 'chatter', 'notifier.channel.chat', 'notifier.channel.email', 'notifier.channel.sms'];
2356+
if (false === $messageBus = $config['message_bus']) {
2357+
foreach ($servicesWithBusArgument as $serviceId) {
2358+
if ($container->hasDefinition($serviceId)) {
2359+
$container->getDefinition($serviceId)->replaceArgument(1, null);
2360+
}
2361+
}
2362+
} else {
2363+
foreach ($servicesWithBusArgument as $serviceId) {
2364+
if ($container->hasDefinition($serviceId)) {
2365+
$container->getDefinition($serviceId)->setArgument(0, null);
2366+
$container->getDefinition($serviceId)->replaceArgument(1, $messageBus ? new Reference($messageBus) : new Reference('messenger.default_bus', ContainerInterface::NULL_ON_INVALID_REFERENCE));
2367+
}
2368+
}
2369+
}
2370+
23552371
if ($this->messengerConfigEnabled) {
23562372
if ($config['notification_on_failed_messages']) {
23572373
$container->getDefinition('notifier.failed_message_listener')->addTag('kernel.event_subscriber');
23582374
}
2359-
2360-
// as we have a bus, the channels don't need the transports
2361-
$container->getDefinition('notifier.channel.chat')->setArgument(0, null);
2362-
if ($container->hasDefinition('notifier.channel.email')) {
2363-
$container->getDefinition('notifier.channel.email')->setArgument(0, null);
2364-
}
2365-
$container->getDefinition('notifier.channel.sms')->setArgument(0, null);
23662375
}
23672376

23682377
$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+
]);
Lines changed: 16 additions & 0 deletions
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+
]);
Lines changed: 16 additions & 0 deletions
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+
]);
Lines changed: 28 additions & 0 deletions
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+
]);

0 commit comments

Comments
 (0)