vendor/liip/functional-test-bundle/src/EventListener/ExceptionListener.php line 44

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of the Liip/FunctionalTestBundle
  5.  *
  6.  * (c) Lukas Kahwe Smith <smith@pooteeweet.org>
  7.  *
  8.  * This source file is subject to the MIT license that is bundled
  9.  * with this source code in the file LICENSE.
  10.  */
  11. namespace Liip\FunctionalTestBundle\EventListener;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. use Symfony\Component\HttpKernel\Event\ExceptionEvent;
  14. use Symfony\Component\HttpKernel\Event\GetResponseEvent;
  15. use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
  16. use Symfony\Component\HttpKernel\Event\RequestEvent;
  17. use Symfony\Component\HttpKernel\HttpKernelInterface;
  18. use Symfony\Component\HttpKernel\KernelEvents;
  19. if (class_exists(ExceptionEvent::class) && !class_exists(GetResponseForExceptionEvent::class)) {
  20.     class_alias(ExceptionEvent::class, GetResponseForExceptionEvent::class);
  21. }
  22. if (class_exists(RequestEvent::class) && !class_exists(GetResponseEvent::class)) {
  23.     class_alias(RequestEvent::class, GetResponseEvent::class);
  24. }
  25. final class ExceptionListener implements EventSubscriberInterface
  26. {
  27.     /**
  28.      * @var \Throwable|null
  29.      */
  30.     private $lastException;
  31.     public function setException(GetResponseForExceptionEvent $event): void
  32.     {
  33.         $this->lastException method_exists($event'getThrowable') ? $event->getThrowable() : $event->getException();
  34.     }
  35.     public function clearLastException(GetResponseEvent $event): void
  36.     {
  37.         if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
  38.             $this->lastException null;
  39.         }
  40.     }
  41.     public function getLastException(): ?\Throwable
  42.     {
  43.         return $this->lastException;
  44.     }
  45.     public static function getSubscribedEvents(): array
  46.     {
  47.         return [
  48.             KernelEvents::EXCEPTION => ['setException'99999],
  49.             KernelEvents::REQUEST => ['clearLastException'99999],
  50.         ];
  51.     }
  52. }