Merge branch 'release/3.4'

This commit is contained in:
Dylan K. Taylor 2018-11-11 19:52:05 +00:00
commit 3031128520
2 changed files with 21 additions and 3 deletions

View File

@ -481,11 +481,14 @@ class PluginManager{
if(count($parameters) !== 1){ if(count($parameters) !== 1){
continue; continue;
} }
$handlerClosure = $method->getClosure($listener);
try{ try{
$eventClass = $parameters[0]->getClass(); $eventClass = $parameters[0]->getClass();
}catch(\ReflectionException $e){ //class doesn't exist }catch(\ReflectionException $e){ //class doesn't exist
if(isset($tags["softDepend"]) && !isset($this->plugins[$tags["softDepend"]])){ if(isset($tags["softDepend"]) && !isset($this->plugins[$tags["softDepend"]])){
$this->server->getLogger()->debug("Not registering @softDepend listener " . get_class($listener) . "::" . $method->getName() . "(" . $parameters[0]->getType()->getName() . ") because plugin \"" . $tags["softDepend"] . "\" not found"); $this->server->getLogger()->debug("Not registering @softDepend listener " . Utils::getNiceClosureName($handlerClosure) . "(" . $parameters[0]->getType()->getName() . ") because plugin \"" . $tags["softDepend"] . "\" not found");
continue; continue;
} }
@ -498,7 +501,7 @@ class PluginManager{
try{ try{
$priority = isset($tags["priority"]) ? EventPriority::fromString($tags["priority"]) : EventPriority::NORMAL; $priority = isset($tags["priority"]) ? EventPriority::fromString($tags["priority"]) : EventPriority::NORMAL;
}catch(\InvalidArgumentException $e){ }catch(\InvalidArgumentException $e){
throw new PluginException("Event handler " . get_class($listener) . "->" . $method->getName() . "() declares invalid/unknown priority \"" . $tags["priority"] . "\""); throw new PluginException("Event handler " . Utils::getNiceClosureName($handlerClosure) . "() declares invalid/unknown priority \"" . $tags["priority"] . "\"");
} }
$ignoreCancelled = false; $ignoreCancelled = false;
@ -512,7 +515,7 @@ class PluginManager{
$ignoreCancelled = false; $ignoreCancelled = false;
break; break;
default: default:
throw new PluginException("Event handler " . get_class($listener) . "->" . $method->getName() . "() declares invalid @ignoreCancelled value \"" . $tags["ignoreCancelled"] . "\""); throw new PluginException("Event handler " . Utils::getNiceClosureName($handlerClosure) . "() declares invalid @ignoreCancelled value \"" . $tags["ignoreCancelled"] . "\"");
} }
} }

View File

@ -62,6 +62,21 @@ class Utils{
*/ */
public static function getNiceClosureName(\Closure $closure) : string{ public static function getNiceClosureName(\Closure $closure) : string{
$func = new \ReflectionFunction($closure); $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(); return "closure@" . self::cleanPath($func->getFileName()) . "#L" . $func->getStartLine();
} }