src/EventSubscriber/Promocode/SenderSubscriber.php line 47

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber\Promocode;
  3. use MLDev\FormBundle\Service\MailerProvider;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpFoundation\RequestStack;
  7. use Twig\Environment;
  8. class SenderSubscriber implements EventSubscriberInterface
  9. {
  10.     /**
  11.      * @var Request|null
  12.      */
  13.     private $request;
  14.     /**
  15.      * @var Environment
  16.      */
  17.     private $templating;
  18.     /**
  19.      * @var MailerProvider
  20.      */
  21.     private $mailerProvider;
  22.     /**
  23.      * FormConfirmSuccessSubscriber constructor.
  24.      */
  25.     public function __construct(RequestStack $requestStackEnvironment $twigMailerProvider $mailerProvider)
  26.     {
  27.         $this->request $requestStack->getCurrentRequest();
  28.         $this->templating $twig;
  29.         $this->mailerProvider $mailerProvider;
  30.     }
  31.     public static function getSubscribedEvents(): array
  32.     {
  33.         return [
  34.             SenderEvent::EVENT_NAME => [
  35.                 ['sendPromocodeForUser'10]
  36.             ]
  37.         ];
  38.     }
  39.     public function sendPromocodeForUser(SenderEvent $event): void
  40.     {
  41.         $body $this->templating->render(
  42.             'promocode/send_promocode_for_user.html.twig', ['promocode' => $event->getPromocode()]
  43.         );
  44.         $message $this->mailerProvider->createMessage('Ваш промокод от Somelove.ru', [
  45.             $event->getPromocode()->getEmail()
  46.         ]);
  47.         $message->addPart(
  48.             $body'text/html'
  49.         );
  50.         $this->mailerProvider->send($message);
  51.     }
  52. }