src/EventSubscriber/UserSubscriber.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\EventListener\UserEvent;
  4. use App\Service\ServiceMailer;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. class UserSubscriber implements EventSubscriberInterface
  7. {
  8.    protected $serviceMailer;
  9.     public function __construct(ServiceMailer $serviceMailer) {
  10.         $this->serviceMailer $serviceMailer;
  11.     }
  12.     
  13.     public function onSendRegistrationUser(UserEvent $userEvent)
  14.     {
  15.         $user $userEvent->getUser();
  16.         $parameters = [
  17.             "nom"=>$user->getNom(),
  18.             "prenom"=> $user->getPrenom(),
  19.             "email"=> $user->getEmail(),
  20.             "token"=> $user->getToken(),
  21.             "userId"=>$user->getId()
  22.            
  23.         ];
  24.         $this->serviceMailer->sendEmail(
  25.             'Enregistrement',
  26.             $userEvent->getEmailFrom(),
  27.             $user->getEmail(),
  28.             UserEvent::TEMPLATE_EMAIL_REGISTRATION_USERS,
  29.             $parameters
  30.             
  31.         );
  32.     }
  33.     public static function getSubscribedEvents() : array
  34.     {
  35.         return[
  36.             UserEvent::class=>[
  37.                 ['onSendRegistrationUser'1]
  38.             ]
  39.         ];
  40.     }