src/EventSubscriber/Subscriber/UserEmailSubscriber.php line 44

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber\Subscriber;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use App\EventSubscriber\Event\UserEvent;
  5. use App\EventSubscriber\CustomEvents;
  6. use App\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_INVITATION => [
  24.                 [
  25.                     'dispatchInvitationEmail',
  26.                     // Define the priority if necessary
  27.                 ],
  28.             ],
  29.         ];
  30.     }
  31.     /**
  32.      * Dispatch an email once a user is created. This allow him/her to create a password and
  33.      * access the account.
  34.      *
  35.      * @param UserEvent $event
  36.      */
  37.     public function dispatchInvitationEmail(UserEvent $event)
  38.     {
  39.         $this->mailer->sendInvitationEmail($event->getUser(), false);
  40.     }
  41. }