<?php
namespace App\EventSubscriber\Promocode;
use MLDev\FormBundle\Service\MailerProvider;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Twig\Environment;
class SenderSubscriber implements EventSubscriberInterface
{
/**
* @var Request|null
*/
private $request;
/**
* @var Environment
*/
private $templating;
/**
* @var MailerProvider
*/
private $mailerProvider;
/**
* FormConfirmSuccessSubscriber constructor.
*/
public function __construct(RequestStack $requestStack, Environment $twig, MailerProvider $mailerProvider)
{
$this->request = $requestStack->getCurrentRequest();
$this->templating = $twig;
$this->mailerProvider = $mailerProvider;
}
public static function getSubscribedEvents(): array
{
return [
SenderEvent::EVENT_NAME => [
['sendPromocodeForUser', 10]
]
];
}
public function sendPromocodeForUser(SenderEvent $event): void
{
$body = $this->templating->render(
'promocode/send_promocode_for_user.html.twig', ['promocode' => $event->getPromocode()]
);
$message = $this->mailerProvider->createMessage('Ваш промокод от Somelove.ru', [
$event->getPromocode()->getEmail()
]);
$message->addPart(
$body, 'text/html'
);
$this->mailerProvider->send($message);
}
}