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

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\GetResponseEvent;
  14. use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
  15. use Symfony\Component\HttpKernel\HttpKernelInterface;
  16. use Symfony\Component\HttpKernel\KernelEvents;
  17. final class ExceptionListener implements EventSubscriberInterface
  18. {
  19.     /**
  20.      * @var \Exception|null
  21.      */
  22.     private $lastException;
  23.     public function setException(GetResponseForExceptionEvent $event): void
  24.     {
  25.         $this->lastException $event->getException();
  26.     }
  27.     public function clearLastException(GetResponseEvent $event): void
  28.     {
  29.         if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
  30.             $this->lastException null;
  31.         }
  32.     }
  33.     public function getLastException(): ?\Exception
  34.     {
  35.         return $this->lastException;
  36.     }
  37.     public static function getSubscribedEvents(): array
  38.     {
  39.         return [
  40.             KernelEvents::EXCEPTION => ['setException'99999],
  41.             KernelEvents::REQUEST => ['clearLastException'99999],
  42.         ];
  43.     }
  44. }