Skip to content

Commit e58e15a

Browse files
committed
[WebProfilerBundle] [FrameworkBundle] profile forward controller action
closes #14358 The `Symfony\Bundle\FrameworkBundle\Controller\Controller::forward()` now passes request attributes to its sub request, so when the profiler will profile the sub request it will add its token to its hold by reference parent request attributes. The profiler main profiler layout displays a shortcut to the forwarded sub request profile which is actually responsible for returning the present response. The web debug toolbar shows a notifying icon, meaning a shortcut to a forwarded profile is available in the toolbar request panel.
1 parent dafc618 commit e58e15a

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

DataCollector/RequestDataCollector.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,18 @@ public function collect(Request $request, Response $response, \Exception $except
141141
'status_text' => Response::$statusTexts[(int) $statusCode],
142142
));
143143
}
144+
145+
if ($parentRequestAttributes = $request->attributes->get('_forwarded')) {
146+
if ($parentRequestAttributes instanceof ParameterBag) {
147+
$parentRequestAttributes->set('_forward_token', $response->headers->get('x-debug-token'));
148+
}
149+
}
150+
if ($request->attributes->has('_forward_controller')) {
151+
$this->data['forward'] = array(
152+
'token' => $request->attributes->get('_forward_token'),
153+
'controller' => $this->parseController($request->attributes->get('_forward_controller')),
154+
);
155+
}
144156
}
145157

146158
public function getPathInfo()
@@ -274,9 +286,26 @@ public function getRedirect()
274286
return isset($this->data['redirect']) ? $this->data['redirect'] : false;
275287
}
276288

289+
/**
290+
* Gets the parsed forward controller.
291+
*
292+
* @return array|bool An array with keys 'token' the forward profile token, and
293+
* 'controller' the parsed forward controller, false otherwise
294+
*/
295+
public function getForward()
296+
{
297+
return isset($this->data['forward']) ? $this->data['forward'] : false;
298+
}
299+
277300
public function onKernelController(FilterControllerEvent $event)
278301
{
279302
$this->controllers[$event->getRequest()] = $event->getController();
303+
304+
if ($parentRequestAttributes = $event->getRequest()->attributes->get('_forwarded')) {
305+
if ($parentRequestAttributes instanceof ParameterBag) {
306+
$parentRequestAttributes->set('_forward_controller', $event->getController());
307+
}
308+
}
280309
}
281310

282311
public static function getSubscribedEvents()

0 commit comments

Comments
 (0)