8000 minor #37204 [FrameworkBundle] Move mailer configuration to php (inst… · symfony/symfony@b5a2af0 · GitHub
[go: up one dir, main page]

Skip to content

Commit b5a2af0

Browse files
committed
minor #37204 [FrameworkBundle] Move mailer configuration to php (instabledesign)
This PR was squashed before being merged into the 5.2-dev branch. Discussion ---------- [FrameworkBundle] Move mailer configuration to php | Q | A | ------------- | --- | Branch? | master | Bug fix? |no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Part of #37186 | License | MIT Move mailer configuration file to php Commits ------- eb88f88 [FrameworkBundle] Move mailer configuration to php
2 parents b04512a + eb88f88 commit b5a2af0

File tree

7 files changed

+178
-119
lines changed

7 files changed

+178
-119
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ public function load(array $configs, ContainerBuilder $container)
356356
}
357357

358358
if ($this->mailerConfigEnabled = $this->isConfigEnabled($container, $config['mailer'])) {
359-
$this->registerMailerConfiguration($config['mailer'], $container, $loader);
359+
$this->registerMailerConfiguration($config['mailer'], $container, $phpLoader);
360360
}
361361

362362
if ($this->isConfigEnabled($container, $config['notifier'])) {
@@ -600,7 +600,7 @@ private function registerProfilerConfiguration(array $config, ContainerBuilder $
600600
}
601601

602602
if ($this->mailerConfigEnabled) {
603-
$loader->load('mailer_debug.xml');
603+
$phpLoader->load('mailer_debug.php');
604604
}
605605

606606
if ($this->httpClientConfigEnabled) {
@@ -1953,14 +1953,14 @@ private function registerHttpClientConfiguration(array $config, ContainerBuilder
19531953
}
19541954
}
19551955

1956-
private function registerMailerConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
1956+
private function registerMailerConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader)
19571957
{
19581958
if (!class_exists(Mailer::class)) {
19591959
throw new LogicException('Mailer support cannot be enabled as the component is not installed. Try running "composer require symfony/mailer".');
19601960
}
19611961

1962-
$loader->load('mailer.xml');
1963-
$loader->load('mailer_transports.xml');
1962+
$loader->load('mailer.php');
1963+
$loader->load('mailer_transports.php');
19641964
if (!\count($config['transports']) && null === $config['dsn']) {
19651965
$config['dsn'] = 'smtp://null';
19661966
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
13+
14+
use Symfony\Component\Mailer\EventListener\EnvelopeListener;
15+
use Symfony\Component\Mailer\EventListener\MessageListener;
16+
use Symfony\Component\Mailer\EventListener\MessageLoggerListener;
17+
use Symfony\Component\Mailer\Mailer;
18+
use Symfony\Component\Mailer\MailerInterface;
19+
use Symfony\Component\Mailer\Messenger\MessageHandler;
20+
use Symfony\Component\Mailer\Transport;
21+
use Symfony\Component\Mailer\Transport\TransportInterface;
22+
use Symfony\Component\Mailer\Transport\Transports;
23+
24+
return static function (ContainerConfigurator $container) {
25+
$container->services()
26+
->set('mailer.mailer', Mailer::class)
27+
->args([
28+
service('mailer.transports'),
29+
abstract_arg('message bus'),
30+
service('event_dispatcher')->ignoreOnInvalid(),
31+
])
32+
->alias('mailer', 'mailer.mailer')
33+
->alias(MailerInterface::class, 'mailer.mailer')
34+
35+
->set('mailer.transports', Transports::class)
36+
->factory([service('mailer.transport_factory'), 'fromStrings'])
37+
->args([
38+
abstract_arg('transports'),
39+
])
40+
41+
->set('mailer.transport_factory', Transport::class)
42+
->args([
43+
tagged_iterator('mailer.transport_factory'),
44+
])
45+
46+
->set('mailer.default_transport', TransportInterface::class)
47+
->factory([service('mailer.transport_factory'), 'fromString'])
48+
->args([
49+
abstract_arg('env(MAILER_DSN)'),
50+
])
51+
->alias(TransportInterface::class, 'mailer.default_transport')
52+
53+
->set('mailer.messenger.message_handler', MessageHandler::class)
54+
->args([
55+
service('mailer.transports'),
56+
])
57+
->tag('messenger.message_handler')
58+
59+
->set('mailer.envelope_listener', EnvelopeListener::class)
60+
->args([
61+
abstract_arg('sender'),
62+
abstract_arg('recipients'),
63+
])
64+
->tag('kernel.event_subscriber')
65+
66+
->set('mailer.message_listener', MessageListener::class)
67+
->args([
68+
abstract_arg('headers'),
69+
])
70+
->tag('kernel.event_subscriber')
71+
72+
->set('mailer.logger_message_listener', MessageLoggerListener::class)
73+
->tag('kernel.event_subscriber')
74+
;
75+
};

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

Lines changed: 0 additions & 51 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
13+
14+
use Symfony\Component\Mailer\DataCollector\MessageDataCollector;
15+
16+
return static function (ContainerConfigurator $container) {
17+
$container->services()
18+
->set('mailer.data_collector', MessageDataCollector::class)
19+
->args([
20+
service('mailer.logger_message_listener'),
21+
])
22+
->tag('data_collector', [
23+
'template' => '@WebProfiler/Collector/mailer.html.twig',
24+
'id' => 'mailer',
25+
])
26+
;
27+
};

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

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
13+
14+
use Symfony\Component\Mailer\Bridge\Amazon\Transport\SesTransportFactory;
15+
use Symfony\Component\Mailer\Bridge\Google\Transport\GmailTransportFactory;
16+
use Symfony\Component\Mailer\Bridge\Mailchimp\Transport\MandrillTransportFactory;
17+
use Symfony\Component\Mailer\Bridge\Mailgun\Transport\MailgunTransportFactory;
18+
use Symfony\Component\Mailer\Bridge\Postmark\Transport\PostmarkTransportFactory;
19+
use Symfony\Component\Mailer\Bridge\Sendgrid\Transport\SendgridTransportFactory;
20+
use Symfony\Component\Mailer\Transport\AbstractTransportFactory;
21+
use Symfony\Component\Mailer\Transport\NullTransportFactory;
22+
use Symfony\Component\Mailer\Transport\SendmailTransportFactory;
23+
use Symfony\Component\Mailer\Transport\Smtp\EsmtpTransportFactory;
24+
25+
return static function (ContainerConfigurator $container) {
26+
$container->services()
27+
->set('mailer.transport_factory.abstract', AbstractTransportFactory::class)
28+
->abstract()
29+
->args([
30+
service('event_dispatcher'),
31+
service('http_client')->ignoreOnInvalid(),
32+
service('logger')->ignoreOnInvalid(),
33+
])
34+
35+
->set('mailer.transport_factory.amazon', SesTransportFactory::class)
36+
->parent('mailer.transport_factory.abstract')
37+
->tag('mailer.transport_factory')
38+
39+
->set('mailer.transport_factory.gmail', GmailTransportFactory::class)
40+
->parent('mailer.transport_factory.abstract')
41+
->tag('mailer.transport_factory')
42+
43+
->set('mailer.transport_factory.mailchimp', MandrillTransportFactory::class)
44+
->parent('mailer.transport_factory.abstract')
45+
->tag('mailer.transport_factory')
46+
47+
->set('mailer.transport_factory.mailgun', MailgunTransportFactory::class)
48+
->parent('mailer.transport_factory.abstract')
49+
->tag('mailer.transport_factory')
50+
51+
->set('mailer.transport_factory.postmark', PostmarkTransportFactory::class)
52+
->parent('mailer.transport_factory.abstract')
53+
->tag('mailer.transport_factory')
54+
55+
->set('mailer.transport_factory.sendgrid', SendgridTransportFactory::class)
56+
->parent('mailer.transport_factory.abstract')
57+
->tag('mailer.transport_factory')
58+
59+
->set('mailer.transport_factory.null', NullTransportFactory::class)
60+
->parent('mailer.transport_factory.abstract')
61+
->tag('mailer.transport_factory')
62+
63+
->set('mailer.transport_factory.sendmail', SendmailTransportFactory::class)
64+
->parent('mailer.transport_factory.abstract')
65+
->tag('mailer.transport_factory')
66+
67+
->set('mailer.transport_factory.smtp', EsmtpTransportFactory::class)
68+
->parent('mailer.transport_factory.abstract')
69+
->tag('mailer.transport_factory', ['priority' => -100])
70+
;
71+
};

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

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)
0