[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.
This commit is contained in:
Jérôme Tamarelle 2013-03-13 23:08:51 +01:00
parent 2453a58d56
commit cce3a6bfca
2 changed files with 13 additions and 2 deletions

View File

@ -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';
}

View File

@ -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(