Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc7f82de

Browse files
committed
feature#39353 [FrameworkBundle][Notifier] Allow to configure or disable the message bus to use (jschaedl, fabpot)
This PR was merged into the 6.3 branch.Discussion----------[FrameworkBundle][Notifier] Allow to configure or disable the message bus to use| Q | A| ------------- | ---| Branch? | 6.3| Bug fix? | no| New feature? | yes <!-- please update src/**/CHANGELOG.md files -->| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->| Tickets | - <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead -->| License | MIT| Doc PR | tbd <!-- required for new features -->For the mailer integration there is already a possibility to disable or configure the `message_bus` to use. See:#34633 and#34648This PR introduces a similar config option `notifier.message_bus` for the notifier integration.Things done:- [x] Add a config option `notifier.message_bus` for the notifier configuration- [x] Adjust FrameworkExtension considering the new `message_bus` config option- [x] Add tests for the new config optionCommits-------fc7aaa6 Fix logic and tests215e802 Allow to configure or disable the message bus to use
2 parentsdc803d7 +fc7aaa6 commitc7f82de

11 files changed

+146
-5
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,6 +2014,9 @@ private function addNotifierSection(ArrayNodeDefinition $rootNode, callable $ena
20142014
->arrayNode('notifier')
20152015
->info('Notifier configuration')
20162016
->{$enableIfStandalone('symfony/notifier', Notifier::class)}()
2017+
->children()
2018+
->scalarNode('message_bus')->defaultNull()->info('The message bus to use. Defaults to the default bus if the Messenger component is installed.')->end()
2019+
->end()
20172020
->fixXmlConfig('chatter_transport')
20182021
->children()
20192022
->arrayNode('chatter_transports')

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2532,6 +2532,18 @@ private function registerNotifierConfiguration(array $config, ContainerBuilder $
25322532
$container->removeDefinition('notifier.channel.email');
25332533
}
25342534

2535+
foreach (['texter','chatter','notifier.channel.chat','notifier.channel.email','notifier.channel.sms']as$serviceId) {
2536+
if (!$container->hasDefinition($serviceId)) {
2537+
continue;
2538+
}
2539+
2540+
if (false ===$messageBus =$config['message_bus']) {
2541+
$container->getDefinition($serviceId)->replaceArgument(1,null);
2542+
}else {
2543+
$container->getDefinition($serviceId)->replaceArgument(1,$messageBus ?newReference($messageBus) :newReference('messenger.default_bus', ContainerInterface::NULL_ON_INVALID_REFERENCE));
2544+
}
2545+
}
2546+
25352547
if ($this->isInitializedConfigEnabled('messenger')) {
25362548
if ($config['notification_on_failed_messages']) {
25372549
$container->getDefinition('notifier.failed_message_listener')->addTag('kernel.event_subscriber');

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

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

5454
->set('notifier.channel.chat', ChatChannel::class)
55-
->args([service('chatter.transports'),service('messenger.default_bus')->ignoreOnInvalid()])
55+
->args([
56+
service('chatter.transports'),
57+
abstract_arg('message bus'),
58+
])
5659
->tag('notifier.channel', ['channel' =>'chat'])
5760

5861
->set('notifier.channel.sms', SmsChannel::class)
59-
->args([service('texter.transports'),service('messenger.default_bus')->ignoreOnInvalid()])
62+
->args([
63+
service('texter.transports'),
64+
abstract_arg('message bus'),
65+
])
6066
->tag('notifier.channel', ['channel' =>'sms'])
6167

6268
->set('notifier.channel.email', EmailChannel::class)
63-
->args([service('mailer.transports'),service('messenger.default_bus')->ignoreOnInvalid()])
69+
->args([
70+
service('mailer.transports'),
71+
abstract_arg('message bus'),
72+
])
6473
->tag('notifier.channel', ['channel' =>'email'])
6574

6675
->set('notifier.channel.push', PushChannel::class)
@@ -76,7 +85,7 @@
7685
->set('chatter', Chatter::class)
7786
->args([
7887
service('chatter.transports'),
79-
service('messenger.default_bus')->ignoreOnInvalid(),
88+
abstract_arg('message bus'),
8089
service('event_dispatcher')->ignoreOnInvalid(),
8190
])
8291

@@ -96,7 +105,7 @@
96105
->set('texter', Texter::class)
97106
->args([
98107
service('texter.transports'),
99-
service('messenger.default_bus')->ignoreOnInvalid(),
108+
abstract_arg('message bus'),
100109
service('event_dispatcher')->ignoreOnInvalid(),
101110
])
102111

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,7 @@ class_exists(SemaphoreStore::class) && SemaphoreStore::isSupported() ? 'semaphor
655655
],
656656
'notifier' => [
657657
'enabled' => !class_exists(FullStack::class) &&class_exists(Notifier::class),
658+
'message_bus' =>null,
658659
'chatter_transports' => [],
659660
'texter_transports' => [],
660661
'channel_policy' => [],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
$container->loadFromExtension('framework', [
4+
'messenger' => [
5+
'enabled' =>true,
6+
],
7+
'mailer' => [
8+
'dsn' =>'smtp://example.com',
9+
],
10+
'notifier' => [
11+
'message_bus' =>false,
12+
'chatter_transports' => [
13+
'test' =>'null'
14+
],
15+
'texter_transports' => [
16+
'test' =>'null'
17+
],
18+
],
19+
]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
$container->loadFromExtension('framework', [
4+
'messenger' => [
5+
'enabled' =>true,
6+
],
7+
'mailer' => [
8+
'dsn' =>'smtp://example.com',
9+
],
10+
'notifier' => [
11+
'message_bus' =>'app.another_bus',
12+
'chatter_transports' => [
13+
'test' =>'null'
14+
],
15+
'texter_transports' => [
16+
'test' =>'null'
17+
],
18+
],
19+
]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" ?>
2+
3+
<containerxmlns="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:messengerenabled="true" />
11+
<framework:mailerdsn="smtp://example.com" />
12+
<framework:notifierenabled="true"message-bus="false">
13+
<framework:chatter-transportname="test">null</framework:chatter-transport>
14+
<framework:texter-transportname="test">null</framework:texter-transport>
15+
</framework:notifier>
16+
</framework:config>
17+
</container>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" ?>
2+
3+
<containerxmlns="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:messengerenabled="true" />
11+
<framework:mailerdsn="smtp://example.com" />
12+
<framework:notifierenabled="true"message-bus="app.another_bus">
13+
<framework:chatter-transportname="test">null</framework:chatter-transport>
14+
<framework:texter-transportname="test">null</framework:texter-transport>
15+
</framework:notifier>
16+
</framework:config>
17+
</container>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
framework:
2+
messenger:
3+
enabled:true
4+
mailer:
5+
dsn:'smtp://example.com'
6+
notifier:
7+
message_bus:false
8+
chatter_transports:
9+
test:'null'
10+
texter_transports:
11+
test:'null'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
framework:
2+
messenger:
3+
enabled:true
4+
mailer:
5+
dsn:'smtp://example.com'
6+
notifier:
7+
message_bus:'app.another_bus'
8+
chatter_transports:
9+
test:'null'
10+
texter_transports:
11+
test:'null'

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2180,6 +2180,28 @@ public function testHtmlSanitizerDefaultConfig()
21802180
$this->assertSame('html_sanitizer', (string)$container->getAlias(HtmlSanitizerInterface::class));
21812181
}
21822182

2183+
publicfunctiontestNotifierWithDisabledMessageBus()
2184+
{
2185+
$container =$this->createContainerFromFile('notifier_with_disabled_message_bus');
2186+
2187+
$this->assertNull($container->getDefinition('chatter')->getArgument(1));
2188+
$this->assertNull($container->getDefinition('texter')->getArgument(1));
2189+
$this->assertNull($container->getDefinition('notifier.channel.chat')->getArgument(1));
2190+
$this->assertNull($container->getDefinition('notifier.channel.email')->getArgument(1));
2191+
$this->assertNull($container->getDefinition('notifier.channel.sms')->getArgument(1));
2192+
}
2193+
2194+
publicfunctiontestNotifierWithSpecificMessageBus()
2195+
{
2196+
$container =$this->createContainerFromFile('notifier_with_specific_message_bus');
2197+
2198+
$this->assertEquals(newReference('app.another_bus'),$container->getDefinition('chatter')->getArgument(1));
2199+
$this->assertEquals(newReference('app.another_bus'),$container->getDefinition('texter')->getArgument(1));
2200+
$this->assertEquals(newReference('app.another_bus'),$container->getDefinition('notifier.channel.chat')->getArgument(1));
2201+
$this->assertEquals(newReference('app.another_bus'),$container->getDefinition('notifier.channel.email')->getArgument(1));
2202+
$this->assertEquals(newReference('app.another_bus'),$container->getDefinition('notifier.channel.sms')->getArgument(1));
2203+
}
2204+
21832205
protectedfunctioncreateContainer(array$data = [])
21842206
{
21852207
returnnewContainerBuilder(newEnvPlaceholderParameterBag(array_merge([

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp