src/EventSubscriber/SendWelcomeEmailSubscriber.php line 52

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Harmonizely\EventSubscriber;
  4. use FOS\UserBundle\Event\GetResponseUserEvent;
  5. use FOS\UserBundle\FOSUserEvents;
  6. use Harmonizely\Core\Exception\BadRequestException;
  7. use Harmonizely\Mailer\InternalMailer;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. use Twig\Error\LoaderError;
  10. use Twig\Error\RuntimeError;
  11. use Twig\Error\SyntaxError;
  12. final class SendWelcomeEmailSubscriber implements EventSubscriberInterface
  13. {
  14.     public const WELCOME_TEMPLATE 'welcome.html.twig';
  15.     /**
  16.      * @var InternalMailer
  17.      */
  18.     private InternalMailer $mailer;
  19.     /**
  20.      * SendWelcomeEmailSubscriber constructor.
  21.      * @param InternalMailer $mailer
  22.      */
  23.     public function __construct(InternalMailer $mailer)
  24.     {
  25.         $this->mailer $mailer;
  26.     }
  27.     /**
  28.      * {@inheritdoc}
  29.      */
  30.     public static function getSubscribedEvents()
  31.     {
  32.         return [
  33.             FOSUserEvents::REGISTRATION_CONFIRM => 'onRegistrationConfirm',
  34.         ];
  35.     }
  36.     /**
  37.      * @param GetResponseUserEvent $event
  38.      * @return void
  39.      * @throws BadRequestException
  40.      * @throws LoaderError
  41.      * @throws RuntimeError
  42.      * @throws SyntaxError
  43.      */
  44.     public function onRegistrationConfirm(GetResponseUserEvent $event): void
  45.     {
  46.         $user $event->getUser();
  47.         $this->mailer->send(
  48.             self::WELCOME_TEMPLATE,
  49.             'Welcome! Quick Call to see if we are the Right Fit?',
  50.             [$user->getEmail() => $user->getFullName()],
  51.             [
  52.                 'user' => $user,
  53.                 'recipient' => $user->getEmail(),
  54.             ],
  55.             'main'
  56.         );
  57.     }
  58. }