Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[HttpKernel][2.6] Adding support for invokable controllers in the Req…
…uestDataCollector
  • Loading branch information
jameshalsall authored and fabpot committed Nov 12, 2014
1 parent 85b016f commit f1d043a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Expand Up @@ -147,6 +147,14 @@ public function collect(Request $request, Response $response, \Exception $except
'file' => $r->getFilename(),
'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 {
$this->data['controller'] = (string) $controller ?: 'n/a';
}
Expand Down
Expand Up @@ -59,6 +59,7 @@ public function testControllerInspection()
// make sure we always match the line number
$r1 = new \ReflectionMethod($this, 'testControllerInspection');
$r2 = new \ReflectionMethod($this, 'staticControllerMethod');
$r3 = new \ReflectionClass($this);
// test name, callable, expected
$controllerTests = array(
array(
Expand Down Expand Up @@ -132,6 +133,17 @@ function () { return 'foo'; },
'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();
Expand Down Expand Up @@ -202,4 +214,9 @@ public static function __callStatic($method, $args)
{
throw new \LogicException('Unexpected method call');
}

public function __invoke()
{
throw new \LogicException('Unexpected method call');
}
}

0 comments on commit f1d043a

Please sign in to comment.