<?php
namespace App\EventSubscriber\Subscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use App\EventSubscriber\Event\UserEvent;
use App\EventSubscriber\CustomEvents;
use App\Mailer\SecurityMailer;
class UserEmailSubscriber implements EventSubscriberInterface
{
/**
* @var SecurityMailer
*/
private $mailer;
public function __construct(SecurityMailer $mailer)
{
$this->mailer = $mailer;
}
/**
* @return array
*/
public static function getSubscribedEvents()
{
return [
CustomEvents::USER_INVITATION => [
[
'dispatchInvitationEmail',
// Define the priority if necessary
],
],
];
}
/**
* Dispatch an email once a user is created. This allow him/her to create a password and
* access the account.
*
* @param UserEvent $event
*/
public function dispatchInvitationEmail(UserEvent $event)
{
$this->mailer->sendInvitationEmail($event->getUser(), false);
}
}