mailer.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\DependencyInjection\Loader\Configurator;
  11. use Symfony\Component\Mailer\EventListener\EnvelopeListener;
  12. use Symfony\Component\Mailer\EventListener\MessageListener;
  13. use Symfony\Component\Mailer\EventListener\MessageLoggerListener;
  14. use Symfony\Component\Mailer\Mailer;
  15. use Symfony\Component\Mailer\MailerInterface;
  16. use Symfony\Component\Mailer\Messenger\MessageHandler;
  17. use Symfony\Component\Mailer\Transport;
  18. use Symfony\Component\Mailer\Transport\TransportInterface;
  19. use Symfony\Component\Mailer\Transport\Transports;
  20. return static function (ContainerConfigurator $container) {
  21. $container->services()
  22. ->set('mailer.mailer', Mailer::class)
  23. ->args([
  24. service('mailer.transports'),
  25. abstract_arg('message bus'),
  26. service('event_dispatcher')->ignoreOnInvalid(),
  27. ])
  28. ->alias('mailer', 'mailer.mailer')
  29. ->alias(MailerInterface::class, 'mailer.mailer')
  30. ->set('mailer.transports', Transports::class)
  31. ->factory([service('mailer.transport_factory'), 'fromStrings'])
  32. ->args([
  33. abstract_arg('transports'),
  34. ])
  35. ->set('mailer.transport_factory', Transport::class)
  36. ->args([
  37. tagged_iterator('mailer.transport_factory'),
  38. ])
  39. ->set('mailer.default_transport', TransportInterface::class)
  40. ->factory([service('mailer.transport_factory'), 'fromString'])
  41. ->args([
  42. abstract_arg('env(MAILER_DSN)'),
  43. ])
  44. ->alias(TransportInterface::class, 'mailer.default_transport')
  45. ->set('mailer.messenger.message_handler', MessageHandler::class)
  46. ->args([
  47. service('mailer.transports'),
  48. ])
  49. ->tag('messenger.message_handler')
  50. ->set('mailer.envelope_listener', EnvelopeListener::class)
  51. ->args([
  52. abstract_arg('sender'),
  53. abstract_arg('recipients'),
  54. ])
  55. ->tag('kernel.event_subscriber')
  56. ->set('mailer.message_listener', MessageListener::class)
  57. ->args([
  58. abstract_arg('headers'),
  59. ])
  60. ->tag('kernel.event_subscriber')
  61. ->set('mailer.logger_message_listener', MessageLoggerListener::class)
  62. ->tag('kernel.event_subscriber')
  63. ->tag('kernel.reset', ['method' => 'reset'])
  64. ->deprecate('symfony/framework-bundle', '5.2', 'The "%service_id%" service is deprecated, use "mailer.message_logger_listener" instead.')
  65. ;
  66. };