mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-17 15:54:23 +00:00
51 lines
1.3 KiB
PHP
51 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/*
|
|
* Chill is a software for social workers
|
|
*
|
|
* For the full copyright and license information, please view
|
|
* the LICENSE file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Chill\MainBundle\Service\Mailer;
|
|
|
|
use Psr\Log\LoggerInterface;
|
|
use Symfony\Component\Mailer\Envelope;
|
|
use Symfony\Component\Mailer\MailerInterface;
|
|
use Symfony\Component\Mime\Address;
|
|
use Symfony\Component\Mime\Email;
|
|
use Symfony\Component\Mime\RawMessage;
|
|
|
|
class ChillMailer implements MailerInterface
|
|
{
|
|
private LoggerInterface $chillLogger;
|
|
|
|
private MailerInterface $initial;
|
|
|
|
private string $prefix = '[Chill] ';
|
|
|
|
public function __construct(MailerInterface $initial, LoggerInterface $chillLogger)
|
|
{
|
|
$this->initial = $initial;
|
|
$this->chillLogger = $chillLogger;
|
|
}
|
|
|
|
public function send(RawMessage $message, ?Envelope $envelope = null): void
|
|
{
|
|
if ($message instanceof Email) {
|
|
$message->subject($this->prefix . $message->getSubject());
|
|
}
|
|
|
|
$this->chillLogger->info('chill email sent', [
|
|
'to' => array_map(static function (Address $address) {
|
|
return $address->getAddress();
|
|
}, $message->getTo()),
|
|
'subject' => $message->getSubject(),
|
|
]);
|
|
|
|
$this->initial->send($message, $envelope);
|
|
}
|
|
}
|