<?php
declare(strict_types=1);
namespace Hitso\Bundle\TicketsBundle\EventListener;
use Hitso\Bundle\CommonBundle\Doctrine\Event\EntityEvent;
use Hitso\Bundle\CommonBundle\Helper\Mailer\MailerHelperInterface;
use Hitso\Bundle\TicketsBundle\Entity\Ticket;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class TicketSubscriber implements EventSubscriberInterface
{
/**
* @var MailerHelperInterface
*/
private $mailerHelper;
public function __construct(MailerHelperInterface $mailerHelper)
{
$this->mailerHelper = $mailerHelper;
}
public static function getSubscribedEvents()
{
return [
'ticket.post_create' => 'onTicketCreate',
];
}
public function onTicketCreate(EntityEvent $event)
{
$ticket = $event->getEntity();
if ($ticket instanceof Ticket) {
$this->mailerHelper->sendEmail([
'recipient' => $ticket->getAuthorEmail(),
'template' => 'HitsoCommonBundle:Mail:layout.html.twig',
'block' => 'mail_ticket_create',
'parameters' => [
'ticket' => $ticket,
],
]);
}
}
}