Skip to content

Commit

Permalink
moved the request data collector to HttpKernel
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Jul 18, 2012
1 parent a7503fb commit 4ce7249
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 98 deletions.

This file was deleted.

Expand Up @@ -6,7 +6,7 @@

<parameters>
<parameter key="data_collector.config.class">Symfony\Component\HttpKernel\DataCollector\ConfigDataCollector</parameter>
<parameter key="data_collector.request.class">Symfony\Bundle\FrameworkBundle\DataCollector\RequestDataCollector</parameter>
<parameter key="data_collector.request.class">Symfony\Component\HttpKernel\DataCollector\RequestDataCollector</parameter>
<parameter key="data_collector.exception.class">Symfony\Component\HttpKernel\DataCollector\ExceptionDataCollector</parameter>
<parameter key="data_collector.events.class">Symfony\Component\HttpKernel\DataCollector\EventDataCollector</parameter>
<parameter key="data_collector.logger.class">Symfony\Component\HttpKernel\DataCollector\LoggerDataCollector</parameter>
Expand All @@ -22,7 +22,7 @@
</service>

<service id="data_collector.request" class="%data_collector.request.class%">
<tag name="kernel.event_listener" event="kernel.controller" method="onKernelController"/>
<tag name="kernel.event_subscriber" />
<tag name="data_collector" template="WebProfilerBundle:Collector:request" id="request" priority="255" />
</service>

Expand Down
Expand Up @@ -17,14 +17,24 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
* RequestDataCollector.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class RequestDataCollector extends DataCollector
class RequestDataCollector extends DataCollector implements EventSubscriberInterface
{
protected $controllers;

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

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -89,7 +99,26 @@ public function collect(Request $request, Response $response, \Exception $except
'session_attributes' => $sessionAttributes,
'flashes' => $flashes,
'path_info' => $request->getPathInfo(),
'controller' => 'n/a',
);

if (isset($this->controllers[$request])) {
$controller = $this->controllers[$request];
if (is_array($controller)) {
$r = new \ReflectionMethod($controller[0], $controller[1]);
$this->data['controller'] = array(
'class' => get_class($controller[0]),
'method' => $controller[1],
'file' => $r->getFilename(),
'line' => $r->getStartLine(),
);
} elseif ($controller instanceof \Closure) {
$this->data['controller'] = 'Closure';
} else {
$this->data['controller'] = (string) $controller ?: 'n/a';
}
unset($this->controllers[$request]);
}
}

public function getPathInfo()
Expand Down Expand Up @@ -167,25 +196,28 @@ public function getFormat()
return $this->data['format'];
}


/**
* Gets the route.
* Gets the route name.
*
* The _route request attributes is automatically set by the Router Matcher.
*
* @return string The route
*/
public function getRoute()
{
return 'n/a';
return isset($this->data['request_attributes']['_route']) ? $this->data['request_attributes']['_route'] : '';
}

/**
* Returns the route parameters.
* Gets the route parameters.
*
* The _route_params request attributes is automatically set by the RouterListener.
*
* @return array The parameters
*/
public function getRouteParams()
{
return 'n/a';
return isset($this->data['request_attributes']['_route_params']) ? $this->data['request_attributes']['_route_params'] : array();
}

/**
Expand All @@ -195,7 +227,17 @@ public function getRouteParams()
*/
public function getController()
{
return 'n/a';
return $this->data['controller'];
}

public function onKernelController(FilterControllerEvent $event)
{
$this->controllers[$event->getRequest()] = $event->getController();
}

public static function getSubscribedEvents()
{
return array(KernelEvents::CONTROLLER => 'onKernelController');
}

/**
Expand Down

0 comments on commit 4ce7249

Please sign in to comment.