vendor/symfony/notifier/Transport/NullTransport.php line 28

Open in your IDE?
  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\Notifier\Transport;
  11. use Symfony\Component\Notifier\Event\MessageEvent;
  12. use Symfony\Component\Notifier\Event\SentMessageEvent;
  13. use Symfony\Component\Notifier\Message\MessageInterface;
  14. use Symfony\Component\Notifier\Message\NullMessage;
  15. use Symfony\Component\Notifier\Message\SentMessage;
  16. use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
  17. /**
  18.  * @author Fabien Potencier <fabien@symfony.com>
  19.  */
  20. class NullTransport implements TransportInterface
  21. {
  22.     private ?EventDispatcherInterface $dispatcher;
  23.     public function __construct(EventDispatcherInterface $dispatcher null)
  24.     {
  25.         $this->dispatcher $dispatcher;
  26.     }
  27.     public function send(MessageInterface $message): SentMessage
  28.     {
  29.         $message = new NullMessage($message);
  30.         $sentMessage = new SentMessage($message, (string) $this);
  31.         if (null === $this->dispatcher) {
  32.             return $sentMessage;
  33.         }
  34.         $this->dispatcher->dispatch(new MessageEvent($message));
  35.         $this->dispatcher->dispatch(new SentMessageEvent($sentMessage));
  36.         return $sentMessage;
  37.     }
  38.     public function __toString(): string
  39.     {
  40.         return 'null';
  41.     }
  42.     public function supports(MessageInterface $message): bool
  43.     {
  44.         return true;
  45.     }
  46. }