src/Infrastructure/Mailing/Subscriber/AuthSubscriber.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Infrastructure\Mailing\Subscriber;
  3. use App\Domain\Password\Event\PasswordResetTokenCreatedEvent;
  4. use App\Infrastructure\Mailing\Mailer;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. class AuthSubscriber implements EventSubscriberInterface
  7. {
  8.     private Mailer $mailer;
  9.     public function __construct(Mailer $mailer)
  10.     {
  11.         $this->mailer $mailer;
  12.     }
  13.     public static function getSubscribedEvents(): array
  14.     {
  15.         return [
  16.             PasswordResetTokenCreatedEvent::class => 'onPasswordRequest'
  17.         ];
  18.     }
  19.     public function onPasswordRequest(PasswordResetTokenCreatedEvent $event): void
  20.     {
  21.         $email $this->mailer->createEmail('mails/auth/password_reset.twig', [
  22.             'token' => $event->getToken()->getToken(),
  23.             'id' => $event->getUser()->getId(),
  24.             'username' => $event->getUser()->getUsername(),
  25.         ])
  26.             ->to($event->getUser()->getEmail())
  27.             ->subject('Mandalas | RĂ©initialisation de votre mot de passe');
  28.         $this->mailer->send($email);
  29.     }
  30. }