vendor/drosalys/api-bundle/src/EventSubscriber/HandleErrorSubscriber.php line 35

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the drosalys/api-bundle package.
  4.  *
  5.  * (c) Benjamin Georgeault
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Drosalys\Bundle\ApiBundle\EventSubscriber;
  11. use Drosalys\Bundle\ApiBundle\Request\ActionRequestTrait;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. use Symfony\Component\HttpKernel\Event\ExceptionEvent;
  14. use Symfony\Component\HttpKernel\KernelEvents;
  15. /**
  16.  * Class HandleErrorSubscriber
  17.  *
  18.  * @author Benjamin Georgeault
  19.  */
  20. class HandleErrorSubscriber implements EventSubscriberInterface
  21. {
  22.     use ActionRequestTrait;
  23.     public static function getSubscribedEvents(): array
  24.     {
  25.         return [
  26.             KernelEvents::EXCEPTION => ['__invoke', -195],
  27.         ];
  28.     }
  29.     public function __invoke(ExceptionEvent $event): void
  30.     {
  31.         if (null === $this->retrieveActionFromRequest($request $event->getRequest())) {
  32.             return;
  33.         }
  34.         $request->setFormat('json');
  35.     }
  36. }