-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[3.1] [WebProfilerBundle] [DX] Feature allow forward and redirection detection in wdt #17589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
fabpot
merged 4 commits into
symfony:master
from
HeahDude:feature-wdt_forward_detection
Mar 31, 2016
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0a1b284
[WebProfiler] [HttpKernel] profile redirections
HeahDude 227ac77
[WebProfilerBundle] [FrameworkBundle] profile forward controller action
HeahDude 4f020b5
[FrameworkBundle] Extends the RequestDataCollector
HeahDude 0a0e8af
[WebProfilerBundle] show the http method in wdt if not 'GET'
HeahDude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
src/Symfony/Bundle/FrameworkBundle/DataCollector/RequestDataCollector.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
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; | ||
|
||
/** | ||
* RequestDataCollector. | ||
* | ||
* @author Jules Pietri <jusles@heahprod.com> | ||
*/ | ||
class RequestDataCollector extends BaseRequestCollector implements EventSubscriberInterface | ||
{ | ||
/** | ||
* {@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'; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
src/Symfony/Bundle/WebProfilerBundle/Resources/views/Icon/forward.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions
10
src/Symfony/Bundle/WebProfilerBundle/Resources/views/Icon/redirect.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be moved to an event listener instead. Otherwise you couldn't track subrequests triggered by user code that doesn't use the base controller class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xabbuh, the point is not to catch subrequests as profiler already does, we can see them in the request panel.
This feature is about catching the "main" forward", using this special method, as it should be used only once in most use case to quickly click the profile token link of the original request in the wdt.
But I can try to go further, how would you imagine the presentation of sub requests token in the wdt ?