vendor/symfony/framework-bundle/DataCollector/RequestDataCollector.php line 59

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <[email protected]>
  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 Symfony\Bundle\FrameworkBundle\DataCollector;
  11. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  12. use Symfony\Component\HttpFoundation\ParameterBag;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\HttpFoundation\Response;
  15. use Symfony\Component\HttpKernel\DataCollector\RequestDataCollector as BaseRequestCollector;
  16. use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
  17. /**
  18.  * RequestDataCollector.
  19.  *
  20.  * @author Jules Pietri <[email protected]>
  21.  */
  22. class RequestDataCollector extends BaseRequestCollector implements EventSubscriberInterface
  23. {
  24.     /**
  25.      * {@inheritdoc}
  26.      */
  27.     public function collect(Request $requestResponse $response, \Exception $exception null)
  28.     {
  29.         parent::collect($request$response$exception);
  30.         if ($parentRequestAttributes $request->attributes->get('_forwarded')) {
  31.             if ($parentRequestAttributes instanceof ParameterBag) {
  32.                 $parentRequestAttributes->set('_forward_token'$response->headers->get('x-debug-token'));
  33.             }
  34.         }
  35.         if ($request->attributes->has('_forward_controller')) {
  36.             $this->data['forward'] = [
  37.                 'token' => $request->attributes->get('_forward_token'),
  38.                 'controller' => $this->parseController($request->attributes->get('_forward_controller')),
  39.             ];
  40.         }
  41.     }
  42.     /**
  43.      * Gets the parsed forward controller.
  44.      *
  45.      * @return array|bool An array with keys 'token' the forward profile token, and
  46.      *                    'controller' the parsed forward controller, false otherwise
  47.      */
  48.     public function getForward()
  49.     {
  50.         return isset($this->data['forward']) ? $this->data['forward'] : false;
  51.     }
  52.     public function onKernelController(FilterControllerEvent $event)
  53.     {
  54.         $this->controllers[$event->getRequest()] = $event->getController();
  55.         if ($parentRequestAttributes $event->getRequest()->attributes->get('_forwarded')) {
  56.             if ($parentRequestAttributes instanceof ParameterBag) {
  57.                 $parentRequestAttributes->set('_forward_controller'$event->getController());
  58.             }
  59.         }
  60.     }
  61.     /**
  62.      * {@inheritdoc}
  63.      */
  64.     public function getName()
  65.     {
  66.         return 'request';
  67.     }
  68. }