<?php
namespace App\EventSubscriber;
use App\Entity\Notif;
use App\Event\NotifEvent;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class NotifSubscriber implements EventSubscriberInterface
{
private $entityManager;
public function __construct(EntityManagerInterface $entityManager)
{
$this->entityManager = $entityManager;
}
/**
* @param NotifEvent $notifEvent
*/
public function onNotifEvent(NotifEvent $notifEvent)
{
$notif = new Notif();
$notif->setRecepient($notifEvent->getNotifRecipient());
$notif->setBody($notifEvent->getNotifBody());
$notif->setCreatedAt(new \DateTime());
$this->entityManager->persist($notif);
$this->entityManager->flush();
}
/**
* @return array|\array[][]
*/
public static function getSubscribedEvents()
{
return [
NotifEvent::class => [['onNotifEvent',0]],
];
}
}