Skip to content

Commit

Permalink
[WebProfilerBundle] Add redirection info to the router panel
Browse files Browse the repository at this point in the history
Conflicts:

	src/Symfony/Bundle/FrameworkBundle/DataCollector/RouterDataCollector.php
	src/Symfony/Bundle/FrameworkBundle/Resources/config/collectors.xml
	src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig
  • Loading branch information
vicb committed Feb 6, 2012
1 parent 826bd23 commit 64ea95d
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 5 deletions.
Expand Up @@ -14,6 +14,9 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
use Symfony\Bundle\FrameworkBundle\Controller\RedirectController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;

/**
* RouterDataCollector.
Expand All @@ -22,11 +25,73 @@
*/
class RouterDataCollector extends DataCollector
{
protected $controllers;

public function __construct()
{
$this->controllers = new \SplObjectStorage();

$this->data = array(
'redirect' => false,
'url' => null,
'route' => null,
);
}

/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
{
if ($response instanceof RedirectResponse) {
$this->data['redirect'] = true;
$this->data['url'] = $response->getTargetUrl();

if ($this->controllers->contains($request)) {
$controller = $this->controllers[$request];
if (is_array($controller)) {
$controller = $controller[0];
}

if ($controller instanceof RedirectController) {
$this->data['route'] = $request->attributes->get('_route', 'n/a');
}
}
}
}

/**
* Remembers the controller associated to each request.
*
* @param FilterControllerEvent The filter controller event
*/
public function onKernelController(FilterControllerEvent $event)
{
$this->controllers[$event->getRequest()] = $event->getController();
}

/**
* @return Boolean Whether this request will result in a redirect
*/
public function getRedirect()
{
return $this->data['redirect'];
}

/**
* @return string|null The target URL
*/
public function getTargetUrl()
{
return $this->data['url'];
}

/**
* @return string|null The target route
*/
public function getTargetRoute()
{
return $this->data['route'];
}

/**
Expand All @@ -36,4 +101,4 @@ public function getName()
{
return 'router';
}
}
}
Expand Up @@ -52,7 +52,8 @@
<tag name="data_collector" template="WebProfilerBundle:Collector:memory" id="memory" priority="255" />
</service>

<service id="data_collector.router" class="%data_collector.router.class%" public="false">
<service id="data_collector.router" class="%data_collector.router.class%" >
<tag name="kernel.event_listener" event="kernel.controller" method="onKernelController"/>
<tag name="data_collector" template="WebProfilerBundle:Collector:router" id="router" priority="255" />
</service>
</services>
Expand Down
Expand Up @@ -46,6 +46,7 @@ public function panelAction($token)

return $this->container->get('templating')->renderResponse('WebProfilerBundle:Router:panel.html.twig', array(
'request' => $request,
'router' => $profile->getCollector('router'),
'traces' => $matcher->getTraces($request->getPathInfo()),
));
}
Expand Down
Expand Up @@ -4,12 +4,20 @@
<li><strong>Route:&nbsp;</strong>{{ request.route }}</li>
<li>
<strong>Route parameters:</strong>
{% include 'WebProfilerBundle:Profiler:table.html.twig' with { 'data': request.routeParams } only %}
{% if request.routeParams|length %}
{% include 'WebProfilerBundle:Profiler:table.html.twig' with { 'data': request.routeParams, 'class': 'inline' } only %}
{% else %}
<em>No parameters</em>
{% endif %}
</li>

{% if router.redirect %}
<li>
<strong>Redirecting to:&nbsp;</strong> "{{ router.targetUrl }}" {% if router.targetRoute %}(route: "{{ router.targetRoute }}"){% endif %}
<li>
{% endif %}
<li>
<strong>Route matching:</strong>
<table class="routing">
<table class="routing inline">
<tr>
<th>Route name</th>
<th>Pattern</th>
Expand Down

0 comments on commit 64ea95d

Please sign in to comment.