vendor/api-platform/core/src/EventListener/ExceptionListener.php line 36

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the API Platform project.
  4.  *
  5.  * (c) Kévin Dunglas <dunglas@gmail.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace ApiPlatform\Core\EventListener;
  12. use ApiPlatform\Core\Util\RequestAttributesExtractor;
  13. use Psr\Log\LoggerInterface;
  14. use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
  15. use Symfony\Component\HttpKernel\EventListener\ExceptionListener as BaseExceptionListener;
  16. /**
  17.  * Handles requests errors.
  18.  *
  19.  * @author Samuel ROZE <samuel.roze@gmail.com>
  20.  * @author Kévin Dunglas <dunglas@gmail.com>
  21.  */
  22. final class ExceptionListener
  23. {
  24.     private $exceptionListener;
  25.     public function __construct($controllerLoggerInterface $logger null$debug false)
  26.     {
  27.         $this->exceptionListener = new BaseExceptionListener($controller$logger$debug);
  28.     }
  29.     public function onKernelException(GetResponseForExceptionEvent $event): void
  30.     {
  31.         $request $event->getRequest();
  32.         // Normalize exceptions only for routes managed by API Platform
  33.         if (
  34.             'html' === $request->getRequestFormat('') ||
  35.             !((RequestAttributesExtractor::extractAttributes($request)['respond'] ?? $request->attributes->getBoolean('_api_respond'false)) || $request->attributes->getBoolean('_graphql'false))
  36.         ) {
  37.             return;
  38.         }
  39.         $this->exceptionListener->onKernelException($event);
  40.     }
  41. }