From f1d043a98a7293e966863214d08275a17281e028 Mon Sep 17 00:00:00 2001 From: James Halsall Date: Mon, 10 Nov 2014 10:45:33 +0000 Subject: [PATCH] [HttpKernel][2.6] Adding support for invokable controllers in the RequestDataCollector --- .../DataCollector/RequestDataCollector.php | 8 ++++++++ .../DataCollector/RequestDataCollectorTest.php | 17 +++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php index f0df74a365a0..d257961e156a 100644 --- a/src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php +++ b/src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php @@ -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'; } diff --git a/src/Symfony/Component/HttpKernel/Tests/DataCollector/RequestDataCollectorTest.php b/src/Symfony/Component/HttpKernel/Tests/DataCollector/RequestDataCollectorTest.php index e10d96c12733..6eeb711d7096 100644 --- a/src/Symfony/Component/HttpKernel/Tests/DataCollector/RequestDataCollectorTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/DataCollector/RequestDataCollectorTest.php @@ -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( @@ -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(); @@ -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'); + } }