<?php
namespace App\EventListener;
use App\Entity\Notification;
use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\RequestEvent;
class NotificationActivitySubscriber implements EventSubscriberInterface {
private $em;
public function __construct(EntityManagerInterface $entityManager)
{
$this->em = $entityManager;
}
public static function getSubscribedEvents()
{
return [
RequestEvent::class => 'onKernelRequest'
];
}
public function onKernelRequest(RequestEvent $event)
{
$notif = $this->em->getRepository(Notification::class)->findOneByUrl($event->getRequest()->getPathInfo());
if($notif !== null){
$notif->setStatut(Notification::STATUT_CLOSE);
$this->em->flush();
}
}
}