src/Subscriber/ContactSubscriber.php line 32

Open in your IDE?
  1. <?php
  2. namespace App\Subscriber;
  3. use App\Infra\Events\ContactEvent;
  4. use App\Infra\Events\SessionMessageEvent;
  5. use App\Infra\Services\MailerService;
  6. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class ContactSubscriber implements EventSubscriberInterface
  9. {
  10.     private $mailerService;
  11.     private $eventDispatcher;
  12.     public static function getSubscribedEvents()
  13.     {
  14.         return [
  15.             contactEvent::CONTACT_SEND_EMAIL => 'contactSendEmail',
  16.         ];
  17.     }
  18.     public function __construct(
  19.          MailerService $mailerService,
  20.          EventDispatcherInterface $eventDispatcher
  21.     ) {
  22.         $this->mailerService $mailerService;
  23.         $this->eventDispatcher $eventDispatcher;
  24.     }
  25.     public function contactSendEmail(ContactEvent $event)
  26.     {
  27.         $this->eventDispatcher->dispatch(
  28.             new SessionMessageEvent(
  29.                 'success',
  30.                 'Votre demande a bien été envoyée'),
  31.             SessionMessageEvent::SESSION_MESSAGE
  32.         );
  33.         $this->mailerService->sendMail(
  34.             $_ENV['ADMIN_MAIL'],
  35.             $event->getContact()->mail,
  36.             $event->getContact()->object,
  37.             'emails/contact_email.html.twig', ['contact' => $event->getContact()]
  38.         );
  39.     }
  40. }