[Mailer] fixed dispatcher not available in Mailer
This commit is contained in:
parent
0c95aad721
commit
77951de0e3
@ -8,6 +8,7 @@
|
||||
<service id="mailer.mailer" class="Symfony\Component\Mailer\Mailer">
|
||||
<argument type="service" id="mailer.default_transport" />
|
||||
<argument type="service" id="messenger.default_bus" on-invalid="ignore" />
|
||||
<argument type="service" id="event_dispatcher" on-invalid="ignore" />
|
||||
</service>
|
||||
<service id="mailer" alias="mailer.mailer" />
|
||||
<service id="Symfony\Component\Mailer\MailerInterface" alias="mailer.mailer" />
|
||||
|
@ -17,6 +17,7 @@ use Symfony\Component\Mailer\Messenger\SendEmailMessage;
|
||||
use Symfony\Component\Mailer\Transport\TransportInterface;
|
||||
use Symfony\Component\Messenger\MessageBusInterface;
|
||||
use Symfony\Component\Mime\RawMessage;
|
||||
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
|
||||
|
||||
/**
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
@ -25,8 +26,9 @@ class Mailer implements MailerInterface
|
||||
{
|
||||
private $transport;
|
||||
private $bus;
|
||||
private $dispatcher;
|
||||
|
||||
public function __construct(TransportInterface $transport, MessageBusInterface $bus = null)
|
||||
public function __construct(TransportInterface $transport, MessageBusInterface $bus = null, EventDispatcherInterface $dispatcher = null)
|
||||
{
|
||||
$this->transport = $transport;
|
||||
$this->bus = $bus;
|
||||
@ -40,6 +42,7 @@ class Mailer implements MailerInterface
|
||||
return;
|
||||
}
|
||||
|
||||
if (null !== $this->dispatcher) {
|
||||
$message = clone $message;
|
||||
if (null !== $envelope) {
|
||||
$envelope = clone $envelope;
|
||||
@ -52,6 +55,7 @@ class Mailer implements MailerInterface
|
||||
}
|
||||
$event = new MessageEvent($message, $envelope, $this->transport->getName());
|
||||
$this->dispatcher->dispatch($event);
|
||||
}
|
||||
|
||||
$this->bus->dispatch(new SendEmailMessage($message, $envelope));
|
||||
}
|
||||
|
Reference in New Issue
Block a user