bundles/mldev-account-bundle/src/Event/Subscriber/RecoverySubscriber.php line 48

Open in your IDE?
  1. <?php
  2. namespace MLDev\AccountBundle\Event\Subscriber;
  3. use MLDev\AccountBundle\Event\RecoveryAccount;
  4. use Swift_Mailer;
  5. use Swift_Message;
  6. use Symfony\Component\DependencyInjection\ContainerInterface;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. use Twig\Environment;
  9. class RecoverySubscriber implements EventSubscriberInterface
  10. {
  11.     /**
  12.      * @var Swift_Mailer
  13.      */
  14.     private $mailer;
  15.     /**
  16.      * @var Environment
  17.      */
  18.     private $twig;
  19.     /**
  20.      * @var array
  21.      */
  22.     private $parameters;
  23.     /**
  24.      * RecoverySubscriber constructor.
  25.      */
  26.     public function __construct(Swift_Mailer $mailerEnvironment $twig, array $parameters)
  27.     {
  28.         $this->parameters $parameters;
  29.         $this->mailer $mailer;
  30.         $this->twig $twig;
  31.     }
  32.     public static function getSubscribedEvents()
  33.     {
  34.         return [
  35.             RecoveryAccount::NOTIFY_AFTER => [
  36.                 ['onNotifyAfter'10]
  37.             ]
  38.         ];
  39.     }
  40.     public function onNotifyAfter(RecoveryAccount $event)
  41.     {
  42.         if (!filter_var($event->getAccount()->getEmail(), FILTER_VALIDATE_EMAIL)) {
  43.             return null;
  44.         }
  45.         $mldevAccountMailFrom $this->parameters['from'] ?? 'info@mldev.ru';
  46.         $message = new Swift_Message('Восстановление пароля');
  47.         $message->setFrom($mldevAccountMailFrom);
  48.         $message->setTo($event->getAccount()->getEmail());
  49.         $message->setBody(
  50.             $this->twig->render(
  51.                 '@MLDevAccount/event/recovery/letter.html.twig', [
  52.                     'account' => $event->getAccount(),
  53.                 ]
  54.             ), 'text/html'
  55.         );
  56.         $this->mailer->send($message);
  57.     }
  58. }