Utils: fixed handling of non-anonymous closure functions

This commit is contained in:
Dylan K. Taylor 2018-11-11 18:51:55 +00:00
parent 2e4143f57e
commit 788b278fc3

View File

@ -62,6 +62,21 @@ class Utils{
*/
public static function getNiceClosureName(\Closure $closure) : string{
$func = new \ReflectionFunction($closure);
if($func->getName() !== "{closure}"){
//closure wraps a named function, can be done with reflection or fromCallable()
//isClosure() is useless here because it just tells us if $func is reflecting a Closure object
$scope = $func->getClosureScopeClass();
if($scope !== null){ //class method
return
$scope->getName() .
($func->getClosureThis() !== null ? "->" : "::") .
$func->getName(); //name doesn't include class in this case
}
//non-class function
return $func->getName();
}
return "closure@" . self::cleanPath($func->getFileName()) . "#L" . $func->getStartLine();
}