vendor/friendsofsymfony/rest-bundle/EventListener/ExceptionListener.php line 33

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the FOSRestBundle package.
  4.  *
  5.  * (c) FriendsOfSymfony <http://friendsofsymfony.github.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. namespace FOS\RestBundle\EventListener;
  11. use FOS\RestBundle\FOSRestBundle;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
  14. use Symfony\Component\HttpKernel\EventListener\ExceptionListener as HttpKernelExceptionListener;
  15. use Symfony\Component\HttpKernel\KernelEvents;
  16. use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
  17. /**
  18.  * ExceptionListener.
  19.  *
  20.  * @author Ener-Getick <egetick@gmail.com>
  21.  *
  22.  * @internal
  23.  */
  24. class ExceptionListener extends HttpKernelExceptionListener
  25. {
  26.     /**
  27.      * {@inheritdoc}
  28.      */
  29.     public function onKernelException(GetResponseForExceptionEvent $event)
  30.     {
  31.         $request $event->getRequest();
  32.         if (!$request->attributes->get(FOSRestBundle::ZONE_ATTRIBUTEtrue)) {
  33.             return;
  34.         }
  35.         parent::onKernelException($event);
  36.     }
  37.     /**
  38.      * {@inheritdoc}
  39.      */
  40.     public static function getSubscribedEvents()
  41.     {
  42.         return array(
  43.             KernelEvents::EXCEPTION => array('onKernelException', -100),
  44.         );
  45.     }
  46.     /**
  47.      * {@inheritdoc}
  48.      */
  49.     protected function duplicateRequest(\Exception $exceptionRequest $request)
  50.     {
  51.         $attributes = array(
  52.             '_controller' => $this->controller,
  53.             'exception' => $exception,
  54.             'logger' => $this->logger instanceof DebugLoggerInterface $this->logger null,
  55.         );
  56.         $request $request->duplicate(nullnull$attributes);
  57.         $request->setMethod('GET');
  58.         return $request;
  59.     }
  60. }