Skip to content

Commit 4677f23

Browse files
ro0NLfabpot
authored andcommitted
[WebProfilerBundle] Imply forward request by a new X-Previous-Debug-Token header
1 parent 7b42c00 commit 4677f23

File tree

5 files changed

+9
-60
lines changed

5 files changed

+9
-60
lines changed

CHANGELOG.md

Lines 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

Controller/ControllerTrait.php

Lines 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

DataCollector/RequestDataCollector.php

Lines 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 <[email protected]>
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
}

Resources/config/collectors.xml

Lines 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>

Tests/Functional/Bundle/TestBundle/Controller/SubRequestServiceResolutionController.php

Lines 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

0 commit comments

Comments
 (0)