<?php
/*
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential.
*
* @author Bilel AZRI <azri.bilel@gmail.com>
* @author Assma BEN SASSI <bensassiasma.bws@gmail.com>
*
* Bicking man (c) 2019-present.
*/
declare(strict_types=1);
namespace App\EventSubscriber\Mailer;
use App\Event\UserResetPasswordUpdatedEvent;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Address;
use Twig\Environment;
final class UserResetPasswordUpdatedSubscriber implements EventSubscriberInterface
{
private $senderEmail;
private $mailer;
private $twig;
private $senderName;
public function __construct(MailerInterface $mailer, Environment $twig, string $senderEmail, string $senderName)
{
$this->mailer = $mailer;
$this->twig = $twig;
$this->senderEmail = $senderEmail;
$this->senderName = $senderName;
}
public static function getSubscribedEvents()
{
return [UserResetPasswordUpdatedEvent::NAME => 'sendMailToUser'];
}
public function sendMailToUser(UserResetPasswordUpdatedEvent $event): void
{
$user = $event->getUser();
$emailContent = $this->twig->render('emails/user/reset_password_updated.html.twig',
['user' => $user]);
$email = (new TemplatedEmail())
->from(new Address($this->senderEmail, $this->senderName))
->to((string) $user->getEmail())
->subject('Password updated!')
->html($emailContent)
;
$this->mailer->send($email);
}
}