[HttpKernel][2.6] Adding support for invokable controllers in the RequestDataCollector

This commit is contained in:
James Halsall 2014-11-10 10:45:33 +00:00 committed by Fabien Potencier
parent 85b016f37b
commit f1d043a98a
2 changed files with 25 additions and 0 deletions

View File

@ -147,6 +147,14 @@ class RequestDataCollector extends DataCollector implements EventSubscriberInter
'file' => $r->getFilename(), 'file' => $r->getFilename(),
'line' => $r->getStartLine(), 'line' => $r->getStartLine(),
); );
} elseif (is_object($controller)) {
$r = new \ReflectionClass($controller);
$this->data['controller'] = array(
'class' => $r->getName(),
'method' => null,
'file' => $r->getFileName(),
'line' => $r->getStartLine(),
);
} else { } else {
$this->data['controller'] = (string) $controller ?: 'n/a'; $this->data['controller'] = (string) $controller ?: 'n/a';
} }

View File

@ -59,6 +59,7 @@ class RequestDataCollectorTest extends \PHPUnit_Framework_TestCase
// make sure we always match the line number // make sure we always match the line number
$r1 = new \ReflectionMethod($this, 'testControllerInspection'); $r1 = new \ReflectionMethod($this, 'testControllerInspection');
$r2 = new \ReflectionMethod($this, 'staticControllerMethod'); $r2 = new \ReflectionMethod($this, 'staticControllerMethod');
$r3 = new \ReflectionClass($this);
// test name, callable, expected // test name, callable, expected
$controllerTests = array( $controllerTests = array(
array( array(
@ -132,6 +133,17 @@ class RequestDataCollectorTest extends \PHPUnit_Framework_TestCase
'line' => 'n/a', 'line' => 'n/a',
), ),
), ),
array(
'Invokable controller',
$this,
array(
'class' => 'Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest',
'method' => null,
'file' => __FILE__,
'line' => $r3->getStartLine(),
),
),
); );
$c = new RequestDataCollector(); $c = new RequestDataCollector();
@ -202,4 +214,9 @@ class RequestDataCollectorTest extends \PHPUnit_Framework_TestCase
{ {
throw new \LogicException('Unexpected method call'); throw new \LogicException('Unexpected method call');
} }
public function __invoke()
{
throw new \LogicException('Unexpected method call');
}
} }