[WebProfilerBundle] Add redirection info to the router panel
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
This commit is contained in:
parent
826bd230a1
commit
64ea95dea1
@ -14,6 +14,9 @@ namespace Symfony\Bundle\FrameworkBundle\DataCollector;
|
|||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
|
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\RedirectController;
|
||||||
|
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||||
|
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RouterDataCollector.
|
* RouterDataCollector.
|
||||||
@ -22,11 +25,73 @@ use Symfony\Component\HttpKernel\DataCollector\DataCollector;
|
|||||||
*/
|
*/
|
||||||
class RouterDataCollector extends DataCollector
|
class RouterDataCollector extends DataCollector
|
||||||
{
|
{
|
||||||
|
protected $controllers;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->controllers = new \SplObjectStorage();
|
||||||
|
|
||||||
|
$this->data = array(
|
||||||
|
'redirect' => false,
|
||||||
|
'url' => null,
|
||||||
|
'route' => null,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function collect(Request $request, Response $response, \Exception $exception = null)
|
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'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,4 +101,4 @@ class RouterDataCollector extends DataCollector
|
|||||||
{
|
{
|
||||||
return 'router';
|
return 'router';
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -52,7 +52,8 @@
|
|||||||
<tag name="data_collector" template="WebProfilerBundle:Collector:memory" id="memory" priority="255" />
|
<tag name="data_collector" template="WebProfilerBundle:Collector:memory" id="memory" priority="255" />
|
||||||
</service>
|
</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" />
|
<tag name="data_collector" template="WebProfilerBundle:Collector:router" id="router" priority="255" />
|
||||||
</service>
|
</service>
|
||||||
</services>
|
</services>
|
||||||
|
@ -46,6 +46,7 @@ class RouterController extends ContainerAware
|
|||||||
|
|
||||||
return $this->container->get('templating')->renderResponse('WebProfilerBundle:Router:panel.html.twig', array(
|
return $this->container->get('templating')->renderResponse('WebProfilerBundle:Router:panel.html.twig', array(
|
||||||
'request' => $request,
|
'request' => $request,
|
||||||
|
'router' => $profile->getCollector('router'),
|
||||||
'traces' => $matcher->getTraces($request->getPathInfo()),
|
'traces' => $matcher->getTraces($request->getPathInfo()),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,20 @@
|
|||||||
<li><strong>Route: </strong>{{ request.route }}</li>
|
<li><strong>Route: </strong>{{ request.route }}</li>
|
||||||
<li>
|
<li>
|
||||||
<strong>Route parameters:</strong>
|
<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>
|
</li>
|
||||||
|
{% if router.redirect %}
|
||||||
|
<li>
|
||||||
|
<strong>Redirecting to: </strong> "{{ router.targetUrl }}" {% if router.targetRoute %}(route: "{{ router.targetRoute }}"){% endif %}
|
||||||
|
<li>
|
||||||
|
{% endif %}
|
||||||
<li>
|
<li>
|
||||||
<strong>Route matching:</strong>
|
<strong>Route matching:</strong>
|
||||||
<table class="routing">
|
<table class="routing inline">
|
||||||
<tr>
|
<tr>
|
||||||
<th>Route name</th>
|
<th>Route name</th>
|
||||||
<th>Pattern</th>
|
<th>Pattern</th>
|
||||||
|
Reference in New Issue
Block a user