Implemented @notHandler annotation for event handlers - skip registering any handlers with this annotation (#2164)

It is somewhat reasonable to have a function in an event handler which accepts an Event parameter, but is not a handler. For example, multiple event handlers can redirect to the same function to process an event, but this function may not want to receive called events.

There are other ways to get around this, such as making the event handler protected/private, or adding a dummy parameter, but this way is cleaner and more explicit.

Relevant old-repo PR: PocketMine/PocketMine-MP#2143
This commit is contained in:
Dylan K. Taylor 2018-05-04 21:36:58 +01:00 committed by GitHub
parent ae0c1c185f
commit 7565b786e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -744,6 +744,9 @@ class PluginManager{
foreach($reflection->getMethods(\ReflectionMethod::IS_PUBLIC) as $method){
if(!$method->isStatic()){
$tags = self::parseDocComment((string) $method->getDocComment());
if(isset($tags["notHandler"])){
continue;
}
try{
$priority = isset($tags["priority"]) ? EventPriority::fromString($tags["priority"]) : EventPriority::NORMAL;