Skip to content

Commit

Permalink
[Notifier] Dispatch message event in null transport
Browse files Browse the repository at this point in the history
  • Loading branch information
jschaedl authored and fabpot committed Feb 24, 2020
1 parent de15900 commit a0d99ce
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/Symfony/Component/Notifier/Transport/NullTransport.php
Expand Up @@ -11,7 +11,11 @@

namespace Symfony\Component\Notifier\Transport;

use Symfony\Component\EventDispatcher\Event;
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 <fabien@symfony.com>
Expand All @@ -20,8 +24,18 @@
*/
class NullTransport implements TransportInterface
{
private $dispatcher;

public function __construct(EventDispatcherInterface $dispatcher = null)
{
$this->dispatcher = class_exists(Event::class) ? LegacyEventDispatcherProxy::decorate($dispatcher) : $dispatcher;
}

public function send(MessageInterface $message): void
{
if (null !== $this->dispatcher) {
$this->dispatcher->dispatch(new MessageEvent($message));
}
}

public function __toString(): string
Expand Down
Expand Up @@ -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());
Expand Down

0 comments on commit a0d99ce

Please sign in to comment.