src/EventListener/NotificationActivitySubscriber.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use App\Entity\Notification;
  4. use Doctrine\Common\EventSubscriber;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use Symfony\Component\HttpKernel\Event\RequestEvent;
  8. class NotificationActivitySubscriber implements EventSubscriberInterface {
  9. private $em;
  10. public function __construct(EntityManagerInterface $entityManager)
  11. {
  12. $this->em = $entityManager;
  13. }
  14. public static function getSubscribedEvents()
  15. {
  16. return [
  17. RequestEvent::class => 'onKernelRequest'
  18. ];
  19. }
  20. public function onKernelRequest(RequestEvent $event)
  21. {
  22. $notif = $this->em->getRepository(Notification::class)->findOneByUrl($event->getRequest()->getPathInfo());
  23. if($notif !== null){
  24. $notif->setStatut(Notification::STATUT_CLOSE);
  25. $this->em->flush();
  26. }
  27. }
  28. }