8000 [Mailer] Allow to configure or disable the message bus to use · libertjeremy/symfony@42fd0cf · GitHub
[go: up one dir, main page]

Skip to content

Commit 42fd0cf

Browse files
committed
[Mailer] Allow to configure or disable the message bus to use
1 parent 7719fc7 commit 42fd0cf

13 files changed

+77
-1
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
* Marked `MicroKernelTrait::configureRoutes()` as `@internal` and `@final`.
88
* Deprecated not overriding `MicroKernelTrait::configureRouting()`.
9+
* Added a new `mailer.message_bus` option to configure or disable the message bus to use to send mails.
910

1011
5.0.0
1112
-----

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,6 +1469,7 @@ private function addMailerSection(ArrayNodeDefinition $rootNode)
14691469
->end()
14701470
->fixXmlConfig('transport')
14711471
->children()
1472+
->scalarNode('message_bus')->defaultNull()->info('The message bus to use. Defaults to the default bus if the Messenger component is installed.')->end()
14721473
->scalarNode('dsn')->defaultNull()->end()
14731474
->arrayNode('transports')
14741475
->useAttributeAsKey('name')

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,6 +1884,13 @@ private function registerMailerConfiguration(array $config, ContainerBuilder $co
18841884
$container->getDefinition('mailer.transports')->setArgument(0, $transports);
18851885
$container->getDefinition('mailer.default_transport')->setArgument(0, current($transports));
18861886

1887+
$mailer = $container->getDefinition('mailer.mailer');
1888+
if (false === $messageBus = $config['message_bus']) {
1889+
$mailer->replaceArgument(1, null);
1890+
} else {
1891+
$mailer->replaceArgument(1, $messageBus ? new Reference($messageBus) : new Reference('messenger.default_bus', ContainerInterface::NULL_ON_INVALID_REFERENCE));
1892+
}
1893+
18871894
$classToServices = [
18881895
SesTransportFactory::class => 'mailer.transport_factory.amazon',
18891896
GmailTransportFactory::class => 'mailer.transport_factory.gmail',

src/Symfony/Bundle/FrameworkBundle/Resources/config/mailer.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<services>
88
<service id="mailer.mailer" class="Symfony\Component\Mailer\Mailer">
99
<argument type="service" id="mailer.transports" />
10-
<argument type="service" id="messenger.default_bus" on-invalid="ignore" />
10+
<argument /> <!-- message bus-->
1111
<argument type="service" id="event_dispatcher" on-invalid="ignore" />
1212
</service>
1313
<service id="mailer" alias="mailer.mailer" />

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@
549549
<xsd:element name="envelope" type="mailer_envelope" minOccurs="0" maxOccurs="1" />
550550
</xsd:sequence>
551551
<xsd:attribute name="dsn" type="xsd:string" />
552+
<xsd:attribute name="message-bus" type="xsd:string" />
552553
</xsd:complexType>
553554

554555
<xsd:complexType name="mailer_envelope">

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

Lines changed: 1 addition & 0 deletions
A8C6
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ class_exists(SemaphoreStore::class) && SemaphoreStore::isSupported() ? 'semaphor
469469
'dsn' => null,
470470
'transports' => [],
471471
'enabled' => !class_exists(FullStack::class) && class_exists(Mailer::class),
472+
'message_bus' => null,
472473
],
473474
'notifier' => [
474475
'enabled' => !class_exists(FullStack::class) && class_exists(Notifier::class),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
$container->loadFromExtension('framework', [
4+
'mailer' => [
5+
'dsn' => 'smtp://example.com',
6+
'message_bus' => false,
7+
],
8+
]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
$container->loadFromExtension('framework', [
4+
'mailer' => [
5+
'dsn' => 'smtp://example.com',
6+
'message_bus' => 'app.another_bus',
7+
],
8+
]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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" message-bus="false">
11+
</framework:mailer>
12+
</framework:config>
13+
</container>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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" message-bus="app.another_bus">
11+
</framework:mailer>
12+
</framework:config>
13+
</container>

0 commit comments

Comments
 (0)
0