Skip to content

[Notifier] Dispatch message event in null transport #35841

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/Symfony/Component/Notifier/Transport/NullTransport.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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