notifier.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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\Bridge\Monolog\Handler\NotifierHandler;
  12. use Symfony\Component\Notifier\Channel\BrowserChannel;
  13. use Symfony\Component\Notifier\Channel\ChannelPolicy;
  14. use Symfony\Component\Notifier\Channel\ChatChannel;
  15. use Symfony\Component\Notifier\Channel\EmailChannel;
  16. use Symfony\Component\Notifier\Channel\SmsChannel;
  17. use Symfony\Component\Notifier\Chatter;
  18. use Symfony\Component\Notifier\ChatterInterface;
  19. use Symfony\Component\Notifier\EventListener\NotificationLoggerListener;
  20. use Symfony\Component\Notifier\EventListener\SendFailedMessageToNotifierListener;
  21. use Symfony\Component\Notifier\Message\ChatMessage;
  22. use Symfony\Component\Notifier\Message\SmsMessage;
  23. use Symfony\Component\Notifier\Messenger\MessageHandler;
  24. use Symfony\Component\Notifier\Notifier;
  25. use Symfony\Component\Notifier\NotifierInterface;
  26. use Symfony\Component\Notifier\Texter;
  27. use Symfony\Component\Notifier\TexterInterface;
  28. use Symfony\Component\Notifier\Transport;
  29. use Symfony\Component\Notifier\Transport\Transports;
  30. return static function (ContainerConfigurator $container) {
  31. $container->services()
  32. ->set('notifier', Notifier::class)
  33. ->args([tagged_locator('notifier.channel', 'channel'), service('notifier.channel_policy')->ignoreOnInvalid()])
  34. ->alias(NotifierInterface::class, 'notifier')
  35. ->set('notifier.channel_policy', ChannelPolicy::class)
  36. ->args([[]])
  37. ->set('notifier.channel.browser', BrowserChannel::class)
  38. ->args([service('request_stack')])
  39. ->tag('notifier.channel', ['channel' => 'browser'])
  40. ->set('notifier.channel.chat', ChatChannel::class)
  41. ->args([service('chatter.transports'), service('messenger.default_bus')->ignoreOnInvalid()])
  42. ->tag('notifier.channel', ['channel' => 'chat'])
  43. ->set('notifier.channel.sms', SmsChannel::class)
  44. ->args([service('texter.transports'), service('messenger.default_bus')->ignoreOnInvalid()])
  45. ->tag('notifier.channel', ['channel' => 'sms'])
  46. ->set('notifier.channel.email', EmailChannel::class)
  47. ->args([service('mailer.transports'), service('messenger.default_bus')->ignoreOnInvalid()])
  48. ->tag('notifier.channel', ['channel' => 'email'])
  49. ->set('notifier.monolog_handler', NotifierHandler::class)
  50. ->args([service('notifier')])
  51. ->set('notifier.failed_message_listener', SendFailedMessageToNotifierListener::class)
  52. ->args([service('notifier')])
  53. ->set('chatter', Chatter::class)
  54. ->args([
  55. service('chatter.transports'),
  56. service('messenger.default_bus')->ignoreOnInvalid(),
  57. service('event_dispatcher')->ignoreOnInvalid(),
  58. ])
  59. ->alias(ChatterInterface::class, 'chatter')
  60. ->set('chatter.transports', Transports::class)
  61. ->factory([service('chatter.transport_factory'), 'fromStrings'])
  62. ->args([[]])
  63. ->set('chatter.transport_factory', Transport::class)
  64. ->args([tagged_iterator('chatter.transport_factory')])
  65. ->set('chatter.messenger.chat_handler', MessageHandler::class)
  66. ->args([service('chatter.transports')])
  67. ->tag('messenger.message_handler', ['handles' => ChatMessage::class])
  68. ->set('texter', Texter::class)
  69. ->args([
  70. service('texter.transports'),
  71. service('messenger.default_bus')->ignoreOnInvalid(),
  72. service('event_dispatcher')->ignoreOnInvalid(),
  73. ])
  74. ->alias(TexterInterface::class, 'texter')
  75. ->set('texter.transports', Transports::class)
  76. ->factory([service('texter.transport_factory'), 'fromStrings'])
  77. ->args([[]])
  78. ->set('texter.transport_factory', Transport::class)
  79. ->args([tagged_iterator('texter.transport_factory')])
  80. ->set('texter.messenger.sms_handler', MessageHandler::class)
  81. ->args([service('texter.transports')])
  82. ->tag('messenger.message_handler', ['handles' => SmsMessage::class])
  83. ->set('notifier.logger_notification_listener', NotificationLoggerListener::class)
  84. ->tag('kernel.event_subscriber')
  85. ;
  86. };