8000 [Mailer] Allow to configure or disable the message bus to use by ogizanagi · Pull Request #34648 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Mailer] Allow to configure or disable the message bus to use #34648

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ CHANGELOG

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

5.0.0
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,7 @@ private function addMailerSection(ArrayNodeDefinition $rootNode)
->end()
->fixXmlConfig('transport')
->children()
->scalarNode('message_bus')->defaultNull()->info('The message bus to use. Defaults to the default bus if the Messenger component is installed.')->end()
->scalarNode('dsn')->defaultNull()->end()
->arrayNode('transports')
->useAttributeAsKey('name')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1884,6 +1884,13 @@ private function registerMailerConfiguration(array $config, ContainerBuilder $co
$container->getDefinition('mailer.transports')->setArgument(0, $transports);
$container->getDefinition('mailer.default_transport')->setArgument(0, current($transports));

$mailer = $container->getDefinition('mailer.mailer');
if (false === $messageBus = $config['message_bus']) {
$mailer->replaceArgument(1, null);
} else {
$mailer->replaceArgument(1, $messageBus ? new Reference($messageBus) : new Reference('messenger.default_bus', ContainerInterface::NULL_ON_INVALID_REFERENCE));
}

$classToServices = [
SesTransportFactory::class => 'mailer.transport_factory.amazon',
GmailTransportFactory::class => 'mailer.transport_factory.gmail',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<services>
<service id="mailer.mailer" class="Symfony\Component\Mailer\Mailer">
<argument type="service" id="mailer.transports" />
<argument type="service" id="messenger.default_bus" on-invalid="ignore" />
<argument /> <!-- message bus-->
<argument type="service" id="event_dispatcher" on-invalid="ignore" />
</service>
<service id="mailer" alias="mailer.mailer" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@
<xsd:element name="envelope" type="mailer_envelope" minOccurs="0" maxOccurs="1" />
</xsd:sequence>
<xsd:attribute name="dsn" type="xsd:string" />
<xsd:attribute name="message-bus" type="xsd:string" />
</xsd:complexType>

<xsd:complexType name="mailer_envelope">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ class_exists(SemaphoreStore::class) && SemaphoreStore::isSupported() ? 'semaphor
'dsn' => null,
'transports' => [],
'enabled' => !class_exists(FullStack::class) && class_exists(Mailer::class),
'message_bus' => null,
],
'notifier' => [
'enabled' => !class_exists(FullStack::class) && class_exists(Notifier::class),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

$container->loadFromExtension('framework', [
'mailer' => [
'dsn' => 'smtp://example.com',
'message_bus' => false,
],
]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

$container->loadFromExtension('framework', [
'mailer' => [
'dsn' => 'smtp://example.com',
'message_bus' => 'app.another_bus',
],
]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config>
<framework:mailer dsn="smtp://example.com" message-bus="false">
</framework:mailer>
</framework:config>
</container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config>
<framework:mailer dsn="smtp://example.com" message-bus="app.another_bus">
</framework:mailer>
</framework:config>
</container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
framework:
mailer:
dsn: 'smtp://example.com'
message_bus: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
framework:
mailer:
dsn: 'smtp://example.com'
message_bus: app.another_bus
7E7A
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,21 @@ public function testMailer(): void
$l = $container->getDefinition('mailer.envelope_listener');
$this->assertSame('sender@example.org', $l->getArgument(0));
$this->assertSame(['redirected@example.org', 'redirected1@example.org'], $l->getArgument(1));
$this->assertEquals(new Reference('messenger.default_bus', ContainerInterface::NULL_ON_INVALID_REFERENCE), $container->getDefinition('mailer.mailer')->getArgument(1));
}

public function testMailerWithDisabledMessageBus(): void
{
$container = $this->createContainerFromFile('mailer_with_disabled_message_bus');

$this->assertNull($container->getDefinition('mailer.mailer')->getArgument(1));
}

public function testMailerWithSpecificMessageBus(): void
{
$container = $this->createContainerFromFile('mailer_with_specific_message_bus');

$this->assertEquals(new Reference('app.another_bus'), $container->getDefinition('mailer.mailer')->getArgument(1));
}

protected function createContainer(array $data = [])
Expand Down
0