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