<?php
namespace App\EventSubscriber;
use App\EventListener\UserEvent;
use App\Service\ServiceMailer;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class UserSubscriber implements EventSubscriberInterface
{
protected $serviceMailer;
public function __construct(ServiceMailer $serviceMailer) {
$this->serviceMailer = $serviceMailer;
}
public function onSendRegistrationUser(UserEvent $userEvent)
{
$user = $userEvent->getUser();
$parameters = [
"nom"=>$user->getNom(),
"prenom"=> $user->getPrenom(),
"email"=> $user->getEmail(),
"token"=> $user->getToken(),
"userId"=>$user->getId()
];
$this->serviceMailer->sendEmail(
'Enregistrement',
$userEvent->getEmailFrom(),
$user->getEmail(),
UserEvent::TEMPLATE_EMAIL_REGISTRATION_USERS,
$parameters
);
}
public static function getSubscribedEvents() : array
{
return[
UserEvent::class=>[
['onSendRegistrationUser', 1]
]
];
}
}