8000 [FrameworkBundle] Move mailer configuration to php by instabledesign · Pull Request #37204 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
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
8000
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ public function load(array $configs, ContainerBuilder $container)
}

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

if ($this->isConfigEnabled($container, $config['notifier'])) {
Expand All @@ -369,7 +369,7 @@ public function load(array $configs, ContainerBuilder $container)
$this->registerSsiConfiguration($config['ssi'], $container, $loader);
$this->registerFragmentsConfiguration($config['fragments'], $container, $loader);
$this->registerTranslatorConfiguration($config['translator'], $container, $loader, $config['default_locale']);
$this->registerProfilerConfiguration($config['profiler'], $container, $loader);
$this->registerProfilerConfiguration($config['profiler'], $container, $loader, $phpLoader);
$this->registerWorkflowConfiguration($config['workflows'], $container, $loader);
$this->registerDebugConfiguration($config['php_errors'], $container, $loader);
$this->registerRouterConfiguration($config['router'], $container, $loader, $config['translator']['enabled_locales'] ?? []);
Expand Down Expand Up @@ -568,7 +568,7 @@ private function registerFragmentsConfiguration(array $config, ContainerBuilder
$container->setParameter('fragment.path', $config['path']);
}

private function registerProfilerConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
private function registerProfilerConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader, PhpFileLoader $phpLoader)
{
if (!$this->isConfigEnabled($container, $config)) {
// this is needed for the WebProfiler to work even if the profiler is disabled
Expand Down Expand Up @@ -600,7 +600,7 @@ private function registerProfilerConfiguration(array $config, ContainerBuilder $
}

if ($this->mailerConfigEnabled) {
$loader->load('mailer_debug.xml');
$phpLoader->load('mailer_debug.php');
}

if ($this->httpClientConfigEnabled) {
Expand Down Expand Up @@ -1953,14 +1953,14 @@ private function registerHttpClientConfiguration(array $config, ContainerBuilder
}
}

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

$loader->load('mailer.xml');
$loader->load('mailer_transports.xml');
$loader->load('mailer.php');
$loader->load('mailer_transports.php');
if (!\count($config['transports']) && null === $config['dsn']) {
$config['dsn'] = 'smtp://null';
}
Expand Down
75 changes: 75 additions & 0 deletions src/Symfony/Bundle/FrameworkBundle/Resources/config/mailer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Symfony\Component\Mailer\EventListener\EnvelopeListener;
use Symfony\Component\Mailer\EventListener\MessageListener;
use Symfony\Component\Mailer\EventListener\MessageLoggerListener;
use Symfony\Component\Mailer\Mailer;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mailer\Messenger\MessageHandler;
use Symfony\Component\Mailer\Transport;
use Symfony\Component\Mailer\Transport\TransportInterface;
use Symfony\Component\Mailer\Transport\Transports;

return static function (ContainerConfigurator $container) {
$container->services()
->set('mailer.mailer', Mailer::class)
->args([
service('mailer.transports'),
abstract_arg('message bus'),
service('event_dispatcher')->ignoreOnInvalid(),
])
->alias('mailer', 'mailer.mailer')
->alias(MailerInterface::class, 'mailer.mailer')

->set('mailer.transports', Transports::class)
->factory([service('mailer.transport_factory'), 'fromStrings'])
->args([
abstract_arg('transports'),
])

->set('mailer.transport_factory', Transport::class)
->args([
tagged_iterator('mailer.transport_factory'),
])

->set('mailer.default_transport', TransportInterface::class)
->factory([service('mailer.transport_factory'), 'fromString'])
->args([
abstract_arg('env(MAILER_DSN)'),
])
->alias(TransportInterface::class, 'mailer.default_transport')

->set('mailer.messenger.message_handler', MessageHandler::class)
->args([
service('mailer.transports'),
])
->tag('messenger.message_handler')

->set('mailer.envelope_listener', EnvelopeListener::class)
->args([
abstract_arg('sender'),
abstract_arg('recipients'),
])
->tag('kernel.event_subscriber')

->set('mailer.message_listener', MessageListener::class)
->args([
abstract_arg('headers'),
])
->tag('kernel.event_subscriber')

->set('mailer.logger_message_listener', MessageLoggerListener::class)
->tag('kernel.event_subscriber')
;
};
51 changes: 0 additions & 51 deletions src/Symfony/Bundle/FrameworkBundle/Resources/config/mailer.xml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Symfony\Component\Mailer\DataCollector\MessageDataCollector;

return static function (ContainerConfigurator $container) {
$container->services()
->set('mailer.data_collector', MessageDataCollector::class)
->args([
service('mailer.logger_message_listener'),
])
->tag('data_collector', [
'template' => '@WebProfiler/Collector/mailer.html.twig',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please change the order of template and id to be consistent with the other data_collector tags

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'id' => 'mailer',
])
;
};

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Symfony\Component\Mailer\Bridge\Amazon\Transport\SesTransportFactory;
use Symfony\Component\Mailer\Bridge\Google\Transport\GmailTransportFactory;
use Symfony\Component\Mailer\Bridge\Mailchimp\Transport\MandrillTransportFactory;
use Symfony\Component\Mailer\Bridge\Mailgun\Transport\MailgunTransportFactory;
use Symfony\Component\Mailer\Bridge\Postmark\Transport\PostmarkTransportFactory;
use Symfony\Component\Mailer\Bridge\Sendgrid\Transport\SendgridTransportFactory;
use Symfony\Component\Mailer\Transport\AbstractTransportFactory;
use Symfony\Component\Mailer\Transport\NullTransportFactory;
use Symfony\Component\Mailer\Transport\SendmailTransportFactory;
use Symfony\Component\Mailer\Transport\Smtp\EsmtpTransportFactory;

return static function (ContainerConfigurator $container) {
$container->services()
->set('mailer.transport_factory.abstract', AbstractTransportFactory::class)
->abstract()
->args([
service('event_dispatcher'),
service('http_client')->ignoreOnInvalid(),
service('logger')->ignoreOnInvalid(),
])

->set('mailer.transport_factory.amazon', SesTransportFactory::class)
->parent('mailer.transport_factory.abstract')
->tag('mailer.transport_factory')

->set('mailer.transport_factory.gmail', GmailTransportFactory::class)
->parent('mailer.transport_factory.abstract')
->tag('mailer.transport_factory')

->set('mailer.transport_factory.mailchimp', MandrillTransportFactory::class)
->parent('mailer.transport_factory.abstract')
->tag('mailer.transport_factory')

->set('mailer.transport_factory.mailgun', MailgunTransportFactory::class)
->parent('mailer.transport_factory.abstract')
->tag('mailer.transport_factory')

->set('mailer.transport_factory.postmark', PostmarkTransportFactory::class)
->parent('mailer.transport_factory.abstract')
->tag('mailer.transport_factory')

->set('mailer.transport_factory.sendgrid', SendgridTransportFactory::class)
->parent('mailer.transport_factory.abstract')
->tag('mailer.transport_factory')

->set('mailer.transport_factory.null', NullTransportFactory::class)
->parent('mailer.transport_factory.abstract')
->tag('mailer.transport_factory')

->set('mailer.transport_factory.sendmail', SendmailTransportFactory::class)
->parent('mailer.transport_factory.abstract')
->tag('mailer.transport_factory')

->set('mailer.transport_factory.smtp', EsmtpTransportFactory::class)
->parent('mailer.transport_factory.abstract')
->tag('mailer.transport_factory', ['priority' => -100])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should i set string or int value for the priority attribute?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int is fine

;
};

This file was deleted.

0