|
- <?php
-
- namespace Lc\SovBundle\EventListener;
-
- use Symfony\Component\HttpFoundation\Session\SessionInterface;
- use Symfony\Component\HttpKernel\Event\ExceptionEvent;
- use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
-
- class ExceptionListener
- {
-
- public function __construct(
- SessionInterface $session
- ) {
- $this->session = $session;
- }
-
- public function onKernelException(ExceptionEvent $event)
- {
- // You get the exception object from the received event
- $exception = $event->getThrowable();
-
- // On détecte une erreur interne (500), on remove les sessions qui servent de filtre dans l'admin
- if ($exception instanceof HttpExceptionInterface != true) {
- if (!headers_sent()) {
- foreach ($this->session->all() as $key => $s) {
- if (str_contains($key, "_filter")) {
- $this->session->remove($key);
- }
- }
- }
- }
- }
- }
|