src/Sylius/Bundle/UserBundle/EventListener/MailerListener.php line 41

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Sylius package.
  4.  *
  5.  * (c) Paweł Jędrzejewski
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace Sylius\Bundle\UserBundle\EventListener;
  12. use Sylius\Bundle\UserBundle\Mailer\Emails;
  13. use Sylius\Component\Mailer\Sender\SenderInterface;
  14. use Sylius\Component\User\Model\UserInterface;
  15. use Symfony\Component\EventDispatcher\GenericEvent;
  16. class MailerListener
  17. {
  18.     /** @var SenderInterface */
  19.     protected $emailSender;
  20.     public function __construct(SenderInterface $emailSender)
  21.     {
  22.         $this->emailSender $emailSender;
  23.     }
  24.     public function sendResetPasswordTokenEmail(GenericEvent $event): void
  25.     {
  26.         $this->sendEmail($event->getSubject(), Emails::RESET_PASSWORD_TOKEN);
  27.     }
  28.     public function sendResetPasswordPinEmail(GenericEvent $event): void
  29.     {
  30.         $this->sendEmail($event->getSubject(), Emails::RESET_PASSWORD_PIN);
  31.     }
  32.     public function sendVerificationTokenEmail(GenericEvent $event): void
  33.     {
  34.         $this->sendEmail($event->getSubject(), Emails::EMAIL_VERIFICATION_TOKEN);
  35.     }
  36.     protected function sendEmail(UserInterface $userstring $emailCode): void
  37.     {
  38.         $this->emailSender->send($emailCode, [$user->getEmail()], ['user' => $user]);
  39.     }
  40. }