vendor/witalink/starter-bundle/src/EventSubscriber/Subscriber/UserEmailSubscriber.php line 56

Open in your IDE?
  1. <?php
  2. namespace Witalink\StarterBundle\EventSubscriber\Subscriber;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Witalink\StarterBundle\EventSubscriber\Event\UserEvent;
  5. use Witalink\StarterBundle\EventSubscriber\CustomEvents;
  6. use Witalink\StarterBundle\Mailer\SecurityMailer;
  7. class UserEmailSubscriber implements EventSubscriberInterface
  8. {
  9.     /**
  10.      * @var SecurityMailer
  11.      */
  12.     private $mailer;
  13.     public function __construct(SecurityMailer $mailer)
  14.     {
  15.         $this->mailer $mailer;
  16.     }
  17.     /**
  18.      * @return array
  19.      */
  20.     public static function getSubscribedEvents()
  21.     {
  22.         return [
  23.             CustomEvents::USER_REGISTRED => [
  24.                 [
  25.                     'dispatchSelfRegistrationEmail',
  26.                     // Define the priority if necessary
  27.                 ],
  28.             ],
  29.             CustomEvents::USER_CREATED => [
  30.                 [
  31.                     'dispatchRegistrationEmail',
  32.                     // Define the priority if necessary
  33.                 ],
  34.             ],
  35.             CustomEvents::USER_FORGET_PASSWORD => [
  36.                 [
  37.                     'dispatchForgetPasswordEmail',
  38.                     // Define the priority if necessary
  39.                 ],
  40.             ],
  41.         ];
  42.     }
  43.     /**
  44.      * Dispatch an email once a user is created. This allow him/her to create a password and
  45.      * access the account.
  46.      *
  47.      * @param UserEvent $event
  48.      */
  49.     public function dispatchRegistrationEmail(UserEvent $event)
  50.     {
  51.         $this->mailer->sendRegisterEmail($event->getUser(), false);
  52.     }
  53.     public function dispatchSelfRegistrationEmail(UserEvent $event)
  54.     {
  55.         $this->mailer->sendRegisterEmail($event->getUser(), true);
  56.     }
  57.     public function dispatchForgetPasswordEmail(UserEvent $event)
  58.     {
  59.         $this->mailer->sendForgetPasswordEmail($event->getUser());
  60.     }
  61. }