mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-29 19:13:49 +00:00
Automatically execute body renderer when posting an email in Chill
+ adaptation of services which already uses body renderer
This commit is contained in:
@@ -12,9 +12,11 @@ declare(strict_types=1);
|
||||
namespace Chill\MainBundle\Service\Mailer;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
|
||||
use Symfony\Component\Mailer\Envelope;
|
||||
use Symfony\Component\Mailer\MailerInterface;
|
||||
use Symfony\Component\Mime\Address;
|
||||
use Symfony\Component\Mime\BodyRendererInterface;
|
||||
use Symfony\Component\Mime\Email;
|
||||
use Symfony\Component\Mime\RawMessage;
|
||||
|
||||
@@ -22,7 +24,7 @@ class ChillMailer implements MailerInterface
|
||||
{
|
||||
private string $prefix = '[Chill] ';
|
||||
|
||||
public function __construct(private readonly MailerInterface $initial, private readonly LoggerInterface $chillLogger) {}
|
||||
public function __construct(private readonly MailerInterface $initial, private readonly LoggerInterface $chillLogger, private readonly BodyRendererInterface $bodyRenderer) {}
|
||||
|
||||
public function send(RawMessage $message, ?Envelope $envelope = null): void
|
||||
{
|
||||
@@ -30,6 +32,10 @@ class ChillMailer implements MailerInterface
|
||||
$message->subject($this->prefix.$message->getSubject());
|
||||
}
|
||||
|
||||
if ($message instanceof TemplatedEmail) {
|
||||
$this->bodyRenderer->render($message);
|
||||
}
|
||||
|
||||
$this->chillLogger->info('chill email sent', [
|
||||
'to' => array_map(static fn (Address $address) => $address->getAddress(), $message->getTo()),
|
||||
'subject' => $message->getSubject(),
|
||||
|
Reference in New Issue
Block a user