From cce3a6bfca9e61f51ab94b87a17061d65f0f22e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Wed, 13 Mar 2013 23:08:51 +0100 Subject: [PATCH] [HttpKernel] Collect data if the controller is a Closure Use the same format as object methods to describe closures and collect the file and the line where it's been declared. These informations should be added in the views of the webprofiler. --- .../HttpKernel/DataCollector/RequestDataCollector.php | 8 +++++++- .../Tests/DataCollector/RequestDataCollectorTest.php | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php index be898210af..934c8477a5 100644 --- a/src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php +++ b/src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php @@ -133,7 +133,13 @@ class RequestDataCollector extends DataCollector implements EventSubscriberInter } } } elseif ($controller instanceof \Closure) { - $this->data['controller'] = 'Closure'; + $r = new \ReflectionFunction($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 7e31d0626d..133d33a7a3 100644 --- a/src/Symfony/Component/HttpKernel/Tests/DataCollector/RequestDataCollectorTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/DataCollector/RequestDataCollectorTest.php @@ -81,7 +81,12 @@ class RequestDataCollectorTest extends \PHPUnit_Framework_TestCase array( 'Closure', function() { return 'foo'; }, - 'Closure', + array( + 'class' => __NAMESPACE__ . '\{closure}', + 'method' => null, + 'file' => __FILE__, + 'line' => __LINE__ - 5, + ), ), array(