diff --git a/UPGRADE-4.1.md b/UPGRADE-4.1.md index f482308f7258..4c20425c7c51 100644 --- a/UPGRADE-4.1.md +++ b/UPGRADE-4.1.md @@ -16,6 +16,7 @@ FrameworkBundle --------------- * A `RouterInterface` that does not implement the `WarmableInterface` is deprecated and will not be supported in Symfony 5.0. + * The `RequestDataCollector` class has been deprecated and will be removed in Symfony 5.0. Use the `Symfony\Component\HttpKernel\DataCollector\RequestDataCollector` class instead. HttpFoundation -------------- diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md index c09d25b4ad52..ddf6a965179d 100644 --- a/UPGRADE-5.0.md +++ b/UPGRADE-5.0.md @@ -15,6 +15,7 @@ FrameworkBundle --------------- * Using a `RouterInterface` that does not implement the `WarmableInterface` is not supported anymore. + * The `RequestDataCollector` class has been removed. Use the `Symfony\Component\HttpKernel\DataCollector\RequestDataCollector` class instead. HttpFoundation -------------- diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md index 43f518570e92..6d615a013f7a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md @@ -9,7 +9,8 @@ CHANGELOG * Allowed the `Router` to work with any PSR-11 container * Added option in workflow dump command to label graph with a custom label * Using a `RouterInterface` that does not implement the `WarmableInterface` is deprecated and will not be supported in Symfony 5.0. - + * The `RequestDataCollector` class has been deprecated and will be removed in Symfony 5.0. Use the `Symfony\Component\HttpKernel\DataCollector\RequestDataCollector` class instead. + 4.0.0 ----- diff --git a/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerTrait.php b/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerTrait.php index 1fb263f00f4d..2c6cb565d011 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerTrait.php +++ b/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerTrait.php @@ -83,7 +83,6 @@ protected function generateUrl(string $route, array $parameters = array(), int $ protected function forward(string $controller, array $path = array(), array $query = array()): Response { $request = $this->container->get('request_stack')->getCurrentRequest(); - $path['_forwarded'] = $request->attributes; $path['_controller'] = $controller; $subRequest = $request->duplicate($query, null, $path); diff --git a/src/Symfony/Bundle/FrameworkBundle/DataCollector/RequestDataCollector.php b/src/Symfony/Bundle/FrameworkBundle/DataCollector/RequestDataCollector.php index 55355bdee705..53c9bef485f7 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DataCollector/RequestDataCollector.php +++ b/src/Symfony/Bundle/FrameworkBundle/DataCollector/RequestDataCollector.php @@ -11,67 +11,17 @@ namespace Symfony\Bundle\FrameworkBundle\DataCollector; -use Symfony\Component\HttpFoundation\ParameterBag; -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\DataCollector\RequestDataCollector as BaseRequestCollector; -use Symfony\Component\HttpKernel\Event\FilterControllerEvent; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Symfony\Component\HttpKernel\DataCollector\RequestDataCollector as BaseRequestDataCollector; + +@trigger_error(sprintf('The "%s" class is deprecated since version 4.1 and will be removed in Symfony 5.0. Use %s instead.', RequestDataCollector::class, BaseRequestDataCollector::class), E_USER_DEPRECATED); /** * RequestDataCollector. * * @author Jules Pietri + * + * @deprecated since version 4.1, to be removed in Symfony 5.0 */ -class RequestDataCollector extends BaseRequestCollector implements EventSubscriberInterface +class RequestDataCollector extends BaseRequestDataCollector { - /** - * {@inheritdoc} - */ - public function collect(Request $request, Response $response, \Exception $exception = null) - { - parent::collect($request, $response, $exception); - - if ($parentRequestAttributes = $request->attributes->get('_forwarded')) { - if ($parentRequestAttributes instanceof ParameterBag) { - $parentRequestAttributes->set('_forward_token', $response->headers->get('x-debug-token')); - } - } - if ($request->attributes->has('_forward_controller')) { - $this->data['forward'] = array( - 'token' => $request->attributes->get('_forward_token'), - 'controller' => $this->parseController($request->attributes->get('_forward_controller')), - ); - } - } - - /** - * Gets the parsed forward controller. - * - * @return array|bool An array with keys 'token' the forward profile token, and - * 'controller' the parsed forward controller, false otherwise - */ - public function getForward() - { - return isset($this->data['forward']) ? $this->data['forward'] : false; - } - - public function onKernelController(FilterControllerEvent $event) - { - $this->controllers[$event->getRequest()] = $event->getController(); - - if ($parentRequestAttributes = $event->getRequest()->attributes->get('_forwarded')) { - if ($parentRequestAttributes instanceof ParameterBag) { - $parentRequestAttributes->set('_forward_controller', $event->getController()); - } - } - } - - /** - * {@inheritdoc} - */ - public function getName() - { - return 'request'; - } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/collectors.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/collectors.xml index 95d13761ecf5..6d3870c31fb0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/collectors.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/collectors.xml @@ -12,7 +12,7 @@ - + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/SubRequestServiceResolutionController.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/SubRequestServiceResolutionController.php index ae17f605a40f..967eac3140e5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/SubRequestServiceResolutionController.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/SubRequestServiceResolutionController.php @@ -24,7 +24,6 @@ class SubRequestServiceResolutionController implements ContainerAwareInterface public function indexAction() { $request = $this->container->get('request_stack')->getCurrentRequest(); - $path['_forwarded'] = $request->attributes; $path['_controller'] = 'TestBundle:SubRequestServiceResolution:fragment'; $subRequest = $request->duplicate(array(), null, $path); diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig index 57daf555a3eb..f43f1a1c04a7 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig @@ -12,9 +12,10 @@ {% endset %} {% endif %} - {% if collector.forward|default(false) %} + {% if collector.forwardtoken %} + {% set forward_profile = profile.childByToken(collector.forwardtoken) %} {% set forward_handler %} - {{ helper.set_handler(collector.forward.controller) }} + {{ helper.set_handler(forward_profile ? forward_profile.collector('request').controller : 'n/a') }} {% endset %} {% endif %} @@ -24,7 +25,7 @@ {{ collector.statuscode }} {% if collector.route %} {% if collector.redirect %}{{ include('@WebProfiler/Icon/redirect.svg') }}{% endif %} - {% if collector.forward|default(false) %}{{ include('@WebProfiler/Icon/forward.svg') }}{% endif %} + {% if collector.forwardtoken %}{{ include('@WebProfiler/Icon/forward.svg') }}{% endif %} {{ 'GET' != collector.method ? collector.method }} @ {{ collector.route }} {% endif %} @@ -81,7 +82,7 @@ Forwarded to {{ forward_handler }} - ({{ collector.forward.token }}) + ({{ collector.forwardtoken }}) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/layout.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/layout.html.twig index 822323315e37..ff1124bfdeb3 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/layout.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/layout.html.twig @@ -44,18 +44,22 @@ {%- endif %} - {% if request_collector and request_collector.forward|default(false) and request_collector.forward.controller.class is defined -%} - {%- set forward = request_collector.forward -%} - {%- set controller = forward.controller -%} + {% if request_collector and request_collector.forwardtoken -%} + {% set forward_profile = profile.childByToken(request_collector.forwardtoken) %} + {% set controller = forward_profile ? forward_profile.collector('request').controller : 'n/a' %} {%- endif %} diff --git a/src/Symfony/Bundle/WebProfilerBundle/composer.json b/src/Symfony/Bundle/WebProfilerBundle/composer.json index e0f385e89558..df801f033d59 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/composer.json +++ b/src/Symfony/Bundle/WebProfilerBundle/composer.json @@ -17,7 +17,7 @@ ], "require": { "php": "^7.1.3", - "symfony/http-kernel": "~3.4|~4.0", + "symfony/http-kernel": "~4.1", "symfony/routing": "~3.4|~4.0", "symfony/twig-bridge": "~3.4|~4.0", "symfony/var-dumper": "~3.4|~4.0", diff --git a/src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php index 26a22bbedb78..36e5634eeb87 100644 --- a/src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php +++ b/src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php @@ -158,6 +158,10 @@ public function collect(Request $request, Response $response, \Exception $except } $this->data['identifier'] = $this->data['route'] ?: (is_array($this->data['controller']) ? $this->data['controller']['class'].'::'.$this->data['controller']['method'].'()' : $this->data['controller']); + + if ($response->headers->has('x-previous-debug-token')) { + $this->data['forward_token'] = $response->headers->get('x-previous-debug-token'); + } } public function lateCollect() @@ -322,6 +326,11 @@ public function getRedirect() return isset($this->data['redirect']) ? $this->data['redirect'] : false; } + public function getForwardToken() + { + return isset($this->data['forward_token']) ? $this->data['forward_token'] : null; + } + public function onKernelController(FilterControllerEvent $event) { $this->controllers[$event->getRequest()] = $event->getController(); diff --git a/src/Symfony/Component/HttpKernel/Profiler/Profile.php b/src/Symfony/Component/HttpKernel/Profiler/Profile.php index e91a0b0c70e4..f03c872672f5 100644 --- a/src/Symfony/Component/HttpKernel/Profiler/Profile.php +++ b/src/Symfony/Component/HttpKernel/Profiler/Profile.php @@ -216,6 +216,17 @@ public function addChild(Profile $child) $child->setParent($this); } + public function getChildByToken(string $token): ?self + { + foreach ($this->children as $child) { + if ($token === $child->getToken()) { + return $child; + } + } + + return null; + } + /** * Gets a Collector by name. * diff --git a/src/Symfony/Component/HttpKernel/Profiler/Profiler.php b/src/Symfony/Component/HttpKernel/Profiler/Profiler.php index 9152e9927767..a97d63b05f8f 100644 --- a/src/Symfony/Component/HttpKernel/Profiler/Profiler.php +++ b/src/Symfony/Component/HttpKernel/Profiler/Profiler.php @@ -156,6 +156,10 @@ public function collect(Request $request, Response $response, \Exception $except $profile->setIp('Unknown'); } + if ($prevToken = $response->headers->get('X-Debug-Token')) { + $response->headers->set('X-Previous-Debug-Token', $prevToken); + } + $response->headers->set('X-Debug-Token', $profile->getToken()); foreach ($this->collectors as $collector) {