Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a2f7982

Browse filesBrowse files
committed
feature #22447 [WebProfilerBundle] Imply forward request by a new X-Previous-Debug-Token header (ro0NL)
This PR was squashed before being merged into the 4.1-dev branch (closes #22447). Discussion ---------- [WebProfilerBundle] Imply forward request by a new X-Previous-Debug-Token header | Q | A | ------------- | --- | Branch? | 4.1 | New feature? | yes | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | #... <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | symfony/symfony-docs#... <!--highly recommended for new features--> TLDR; imply a "forwarded" request in the profiler if one _returns_ a response with a x-debug-token set. Otherwise dont. ____ Currently a forward request is implied by the WDT/profiler based on the latest sub-request made, however the main request can return it's own response, or one from a non-latest sub-request. The current behavior is a bit misleading imo. ```php public function indexAction(Request $request) { $bar1 = $this->forward(__CLASS__.'::barAction'); $bar2 = $this->forward(__CLASS__.'::bar2Action'); return $bar1; } ``` It shows the request was forwarded to `bar2Action`. This changes that, so that `barAction` is shown instead. No forward is implied if a new response was returned by `indexAction`. ![image](https://cloud.githubusercontent.com/assets/1047696/25064022/e24d999e-21f1-11e7-8f94-afa3fad7462f.png) ~~Note we dont really need the collector in the framework bundle anymore with this approach.~~ deprecated it. Commits ------- 07dd09d [WebProfilerBundle] Imply forward request by a new X-Previous-Debug-Token header
2 parents 06ab73b + 07dd09d commit a2f7982
Copy full SHA for a2f7982

File tree

Expand file treeCollapse file tree

13 files changed

+52
-72
lines changed
Filter options
Expand file treeCollapse file tree

13 files changed

+52
-72
lines changed

‎UPGRADE-4.1.md

Copy file name to clipboardExpand all lines: UPGRADE-4.1.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ FrameworkBundle
1616
---------------
1717

1818
* A `RouterInterface` that does not implement the `WarmableInterface` is deprecated and will not be supported in Symfony 5.0.
19+
* The `RequestDataCollector` class has been deprecated and will be removed in Symfony 5.0. Use the `Symfony\Component\HttpKernel\DataCollector\RequestDataCollector` class instead.
1920

2021
HttpFoundation
2122
--------------

‎UPGRADE-5.0.md

Copy file name to clipboardExpand all lines: UPGRADE-5.0.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ FrameworkBundle
1515
---------------
1616

1717
* Using a `RouterInterface` that does not implement the `WarmableInterface` is not supported anymore.
18+
* The `RequestDataCollector` class has been removed. Use the `Symfony\Component\HttpKernel\DataCollector\RequestDataCollector` class instead.
1819

1920
HttpFoundation
2021
--------------

‎src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ CHANGELOG
99
* Allowed the `Router` to work with any PSR-11 container
1010
* Added option in workflow dump command to label graph with a custom label
1111
* Using a `RouterInterface` that does not implement the `WarmableInterface` is deprecated and will not be supported in Symfony 5.0.
12-
12+
* The `RequestDataCollector` class has been deprecated and will be removed in Symfony 5.0. Use the `Symfony\Component\HttpKernel\DataCollector\RequestDataCollector` class instead.
13+
1314
4.0.0
1415
-----
1516

‎src/Symfony/Bundle/FrameworkBundle/Controller/ControllerTrait.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Controller/ControllerTrait.php
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ protected function generateUrl(string $route, array $parameters = array(), int $
8383
protected function forward(string $controller, array $path = array(), array $query = array()): Response
8484
{
8585
$request = $this->container->get('request_stack')->getCurrentRequest();
86-
$path['_forwarded'] = $request->attributes;
8786
$path['_controller'] = $controller;
8887
$subRequest = $request->duplicate($query, null, $path);
8988

‎src/Symfony/Bundle/FrameworkBundle/DataCollector/RequestDataCollector.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DataCollector/RequestDataCollector.php
+6-56Lines changed: 6 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -11,67 +11,17 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\DataCollector;
1313

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;
14+
use Symfony\Component\HttpKernel\DataCollector\RequestDataCollector as BaseRequestDataCollector;
15+
16+
@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);
2017

2118
/**
2219
* RequestDataCollector.
2320
*
2421
* @author Jules Pietri <jusles@heahprod.com>
22+
*
23+
* @deprecated since version 4.1, to be removed in Symfony 5.0
2524
*/
26-
class RequestDataCollector extends BaseRequestCollector implements EventSubscriberInterface
25+
class RequestDataCollector extends BaseRequestDataCollector
2726
{
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-
}
7727
}

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/collectors.xml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/collectors.xml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<call method="setKernel"><argument type="service" id="kernel" on-invalid="ignore" /></call>
1313
</service>
1414

15-
<service id="data_collector.request" class="Symfony\Bundle\FrameworkBundle\DataCollector\RequestDataCollector">
15+
<service id="data_collector.request" class="Symfony\Component\HttpKernel\DataCollector\RequestDataCollector">
1616
<tag name="kernel.event_subscriber" />
1717
<tag name="data_collector" template="@WebProfiler/Collector/request.html.twig" id="request" priority="335" />
1818
</service>

‎src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/SubRequestServiceResolutionController.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/SubRequestServiceResolutionController.php
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ class SubRequestServiceResolutionController implements ContainerAwareInterface
2424
public function indexAction()
2525
{
2626
$request = $this->container->get('request_stack')->getCurrentRequest();
27-
$path['_forwarded'] = $request->attributes;
2827
$path['_controller'] = 'TestBundle:SubRequestServiceResolution:fragment';
2928
$subRequest = $request->duplicate(array(), null, $path);
3029

‎src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig
+5-4Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
{% endset %}
1313
{% endif %}
1414

15-
{% if collector.forward|default(false) %}
15+
{% if collector.forwardtoken %}
16+
{% set forward_profile = profile.childByToken(collector.forwardtoken) %}
1617
{% set forward_handler %}
17-
{{ helper.set_handler(collector.forward.controller) }}
18+
{{ helper.set_handler(forward_profile ? forward_profile.collector('request').controller : 'n/a') }}
1819
{% endset %}
1920
{% endif %}
2021

@@ -24,7 +25,7 @@
2425
<span class="sf-toolbar-status sf-toolbar-status-{{ request_status_code_color }}">{{ collector.statuscode }}</span>
2526
{% if collector.route %}
2627
{% if collector.redirect %}{{ include('@WebProfiler/Icon/redirect.svg') }}{% endif %}
27-
{% if collector.forward|default(false) %}{{ include('@WebProfiler/Icon/forward.svg') }}{% endif %}
28+
{% if collector.forwardtoken %}{{ include('@WebProfiler/Icon/forward.svg') }}{% endif %}
2829
<span class="sf-toolbar-label">{{ 'GET' != collector.method ? collector.method }} @</span>
2930
<span class="sf-toolbar-value sf-toolbar-info-piece-additional">{{ collector.route }}</span>
3031
{% endif %}
@@ -81,7 +82,7 @@
8182
<b>Forwarded to</b>
8283
<span>
8384
{{ forward_handler }}
84-
(<a href="{{ path('_profiler', { token: collector.forward.token }) }}">{{ collector.forward.token }}</a>)
85+
(<a href="{{ path('_profiler', { token: collector.forwardtoken }) }}">{{ collector.forwardtoken }}</a>)
8586
</span>
8687
</div>
8788
</div>

‎src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/layout.html.twig

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/layout.html.twig
+11-7Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,22 @@
4444
</dl>
4545
{%- endif %}
4646

47-
{% if request_collector and request_collector.forward|default(false) and request_collector.forward.controller.class is defined -%}
48-
{%- set forward = request_collector.forward -%}
49-
{%- set controller = forward.controller -%}
47+
{% if request_collector and request_collector.forwardtoken -%}
48+
{% set forward_profile = profile.childByToken(request_collector.forwardtoken) %}
49+
{% set controller = forward_profile ? forward_profile.collector('request').controller : 'n/a' %}
5050
<dl class="metadata">
5151
<dt>Forwarded to</dt>
5252
<dd>
53-
{% set link = controller.file|file_link(controller.line) -%}
53+
{% set link = controller.file is defined ? controller.file|file_link(controller.line) : null -%}
5454
{%- if link %}<a href="{{ link }}" title="{{ controller.file }}">{% endif -%}
55-
{{- controller.class|abbr_class|striptags -}}
56-
{{- controller.method ? ' :: ' ~ controller.method }}
55+
{% if controller.class is defined %}
56+
{{- controller.class|abbr_class|striptags -}}
57+
{{- controller.method ? ' :: ' ~ controller.method -}}
58+
{% else %}
59+
{{- controller -}}
60+
{% endif %}
5761
{%- if link %}</a>{% endif %}
58-
(<a href="{{ path('_profiler', { token: forward.token }) }}">{{ forward.token }}</a>)
62+
(<a href="{{ path('_profiler', { token: request_collector.forwardtoken }) }}">{{ request_collector.forwardtoken }}</a>)
5963
</dd>
6064
</dl>
6165
{%- endif %}

‎src/Symfony/Bundle/WebProfilerBundle/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/WebProfilerBundle/composer.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
],
1818
"require": {
1919
"php": "^7.1.3",
20-
"symfony/http-kernel": "~3.4|~4.0",
20+
"symfony/http-kernel": "~4.1",
2121
"symfony/routing": "~3.4|~4.0",
2222
"symfony/twig-bridge": "~3.4|~4.0",
2323
"symfony/var-dumper": "~3.4|~4.0",

‎src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ public function collect(Request $request, Response $response, \Exception $except
158158
}
159159

160160
$this->data['identifier'] = $this->data['route'] ?: (is_array($this->data['controller']) ? $this->data['controller']['class'].'::'.$this->data['controller']['method'].'()' : $this->data['controller']);
161+
162+
if ($response->headers->has('x-previous-debug-token')) {
163+
$this->data['forward_token'] = $response->headers->get('x-previous-debug-token');
164+
}
161165
}
162166

163167
public function lateCollect()
@@ -322,6 +326,11 @@ public function getRedirect()
322326
return isset($this->data['redirect']) ? $this->data['redirect'] : false;
323327
}
324328

329+
public function getForwardToken()
330+
{
331+
return isset($this->data['forward_token']) ? $this->data['forward_token'] : null;
332+
}
333+
325334
public function onKernelController(FilterControllerEvent $event)
326335
{
327336
$this->controllers[$event->getRequest()] = $event->getController();

‎src/Symfony/Component/HttpKernel/Profiler/Profile.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Profiler/Profile.php
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,17 @@ public function addChild(Profile $child)
216216
$child->setParent($this);
217217
}
218218

219+
public function getChildByToken(string $token): ?self
220+
{
221+
foreach ($this->children as $child) {
222+
if ($token === $child->getToken()) {
223+
return $child;
224+
}
225+
}
226+
227+
return null;
228+
}
229+
219230
/**
220231
* Gets a Collector by name.
221232
*

‎src/Symfony/Component/HttpKernel/Profiler/Profiler.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Profiler/Profiler.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ public function collect(Request $request, Response $response, \Exception $except
156156
$profile->setIp('Unknown');
157157
}
158158

159+
if ($prevToken = $response->headers->get('X-Debug-Token')) {
160+
$response->headers->set('X-Previous-Debug-Token', $prevToken);
161+
}
162+
159163
$response->headers->set('X-Debug-Token', $profile->getToken());
160164

161165
foreach ($this->collectors as $collector) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.