[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">
|
<service id="mailer.mailer" class="Symfony\Component\Mailer\Mailer">
|
||||||
<argument type="service" id="mailer.default_transport" />
|
<argument type="service" id="mailer.default_transport" />
|
||||||
<argument type="service" id="messenger.default_bus" on-invalid="ignore" />
|
<argument type="service" id="messenger.default_bus" on-invalid="ignore" />
|
||||||
|
<argument type="service" id="event_dispatcher" on-invalid="ignore" />
|
||||||
</service>
|
</service>
|
||||||
<service id="mailer" alias="mailer.mailer" />
|
<service id="mailer" alias="mailer.mailer" />
|
||||||
<service id="Symfony\Component\Mailer\MailerInterface" 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\Mailer\Transport\TransportInterface;
|
||||||
use Symfony\Component\Messenger\MessageBusInterface;
|
use Symfony\Component\Messenger\MessageBusInterface;
|
||||||
use Symfony\Component\Mime\RawMessage;
|
use Symfony\Component\Mime\RawMessage;
|
||||||
|
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
@ -25,8 +26,9 @@ class Mailer implements MailerInterface
|
|||||||
{
|
{
|
||||||
private $transport;
|
private $transport;
|
||||||
private $bus;
|
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->transport = $transport;
|
||||||
$this->bus = $bus;
|
$this->bus = $bus;
|
||||||
@ -40,18 +42,20 @@ class Mailer implements MailerInterface
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$message = clone $message;
|
if (null !== $this->dispatcher) {
|
||||||
if (null !== $envelope) {
|
$message = clone $message;
|
||||||
$envelope = clone $envelope;
|
if (null !== $envelope) {
|
||||||
} else {
|
$envelope = clone $envelope;
|
||||||
try {
|
} else {
|
||||||
$envelope = new DelayedSmtpEnvelope($message);
|
try {
|
||||||
} catch (\Exception $e) {
|
$envelope = new DelayedSmtpEnvelope($message);
|
||||||
throw new TransportException('Cannot send message without a valid envelope.', 0, $e);
|
} catch (\Exception $e) {
|
||||||
|
throw new TransportException('Cannot send message without a valid envelope.', 0, $e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
$event = new MessageEvent($message, $envelope, $this->transport->getName());
|
||||||
|
$this->dispatcher->dispatch($event);
|
||||||
}
|
}
|
||||||
$event = new MessageEvent($message, $envelope, $this->transport->getName());
|
|
||||||
$this->dispatcher->dispatch($event);
|
|
||||||
|
|
||||||
$this->bus->dispatch(new SendEmailMessage($message, $envelope));
|
$this->bus->dispatch(new SendEmailMessage($message, $envelope));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user