You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ExceptionListener.php 939B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. namespace Lc\SovBundle\EventListener;
  3. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  4. use Symfony\Component\HttpKernel\Event\ExceptionEvent;
  5. use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
  6. class ExceptionListener
  7. {
  8. public function __construct(
  9. SessionInterface $session
  10. ) {
  11. $this->session = $session;
  12. }
  13. public function onKernelException(ExceptionEvent $event)
  14. {
  15. // You get the exception object from the received event
  16. $exception = $event->getThrowable();
  17. // On détecte une erreur interne (500), on remove les sessions qui servent de filtre dans l'admin
  18. if ($exception instanceof HttpExceptionInterface != true) {
  19. foreach ($this->session->all() as $key => $s) {
  20. if (str_contains($key, "_filter")) {
  21. $this->session->remove($key);
  22. }
  23. }
  24. }
  25. }
  26. }