mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 15:13:50 +00:00
Improve notifications
This commit is contained in:
50
src/Bundle/ChillMainBundle/Service/Mailer/ChillMailer.php
Normal file
50
src/Bundle/ChillMainBundle/Service/Mailer/ChillMailer.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user