<?php
declare(strict_types=1);
namespace Harmonizely\EventSubscriber;
use FOS\UserBundle\Event\GetResponseUserEvent;
use FOS\UserBundle\FOSUserEvents;
use Harmonizely\Core\Exception\BadRequestException;
use Harmonizely\Mailer\InternalMailer;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError;
final class SendWelcomeEmailSubscriber implements EventSubscriberInterface
{
public const WELCOME_TEMPLATE = 'welcome.html.twig';
/**
* @var InternalMailer
*/
private InternalMailer $mailer;
/**
* SendWelcomeEmailSubscriber constructor.
* @param InternalMailer $mailer
*/
public function __construct(InternalMailer $mailer)
{
$this->mailer = $mailer;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents()
{
return [
FOSUserEvents::REGISTRATION_CONFIRM => 'onRegistrationConfirm',
];
}
/**
* @param GetResponseUserEvent $event
* @return void
* @throws BadRequestException
* @throws LoaderError
* @throws RuntimeError
* @throws SyntaxError
*/
public function onRegistrationConfirm(GetResponseUserEvent $event): void
{
$user = $event->getUser();
$this->mailer->send(
self::WELCOME_TEMPLATE,
'Welcome! Quick Call to see if we are the Right Fit?',
[$user->getEmail() => $user->getFullName()],
[
'user' => $user,
'recipient' => $user->getEmail(),
],
'main'
);
}
}