vendor/contao/core-bundle/src/EventListener/ResponseExceptionListener.php line 26

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of Contao.
  5.  *
  6.  * (c) Leo Feyer
  7.  *
  8.  * @license LGPL-3.0-or-later
  9.  */
  10. namespace Contao\CoreBundle\EventListener;
  11. use Contao\CoreBundle\Exception\ResponseException;
  12. use Symfony\Component\HttpKernel\Event\ExceptionEvent;
  13. /**
  14.  * @internal
  15.  */
  16. class ResponseExceptionListener
  17. {
  18.     /**
  19.      * Sets the response from the exception.
  20.      */
  21.     public function __invoke(ExceptionEvent $event): void
  22.     {
  23.         $exception $event->getThrowable();
  24.         if (!$exception instanceof ResponseException) {
  25.             return;
  26.         }
  27.         $event->allowCustomResponseCode();
  28.         $event->setResponse($exception->getResponse());
  29.     }
  30. }