NullTransport.php 1.3 KB

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