From 3809d90fba57833454e9634a07a3cc67f1372f9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Sch=C3=A4dlich?= Date: Mon, 24 Feb 2020 09:43:05 +0100 Subject: [PATCH] [Notifier] Dispatch message event in null transport --- .../Component/Notifier/Transport/NullTransport.php | 13 +++++++++++++ .../Notifier/Transport/NullTransportFactory.php | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Notifier/Transport/NullTransport.php b/src/Symfony/Component/Notifier/Transport/NullTransport.php index 658243ae7d539..1754eeae891db 100644 --- a/src/Symfony/Component/Notifier/Transport/NullTransport.php +++ b/src/Symfony/Component/Notifier/Transport/NullTransport.php @@ -11,7 +11,10 @@ namespace Symfony\Component\Notifier\Transport; +use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy; +use Symfony\Component\Notifier\Event\MessageEvent; use Symfony\Component\Notifier\Message\MessageInterface; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; /** * @author Fabien Potencier @@ -20,8 +23,18 @@ */ class NullTransport implements TransportInterface { + private $dispatcher; + + public function __construct(EventDispatcherInterface $dispatcher = null) + { + $this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher); + } + public function send(MessageInterface $message): void { + if (null !== $this->dispatcher) { + $this->dispatcher->dispatch(new MessageEvent($message)); + } } public function __toString(): string diff --git a/src/Symfony/Component/Notifier/Transport/NullTransportFactory.php b/src/Symfony/Component/Notifier/Transport/NullTransportFactory.php index abfcd1c75d3f7..196d052a05163 100644 --- a/src/Symfony/Component/Notifier/Transport/NullTransportFactory.php +++ b/src/Symfony/Component/Notifier/Transport/NullTransportFactory.php @@ -26,7 +26,7 @@ final class NullTransportFactory extends AbstractTransportFactory public function create(Dsn $dsn): TransportInterface { if ('null' === $dsn->getScheme()) { - return new NullTransport(); + return new NullTransport($this->dispatcher); } throw new UnsupportedSchemeException($dsn, 'null', $this->getSupportedSchemes());