From 6cb285d4a98baee5e906f92e93fb70eccbd4171e Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 6 May 2021 18:40:14 +0100 Subject: [PATCH] Added constants for the handler tag types --- src/event/ListenerMethodTags.php | 34 ++++++++++++++++++++++++++++++++ src/plugin/PluginManager.php | 13 ++++++------ 2 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 src/event/ListenerMethodTags.php diff --git a/src/event/ListenerMethodTags.php b/src/event/ListenerMethodTags.php new file mode 100644 index 000000000..ba72fc4cf --- /dev/null +++ b/src/event/ListenerMethodTags.php @@ -0,0 +1,34 @@ +getMethods(\ReflectionMethod::IS_PUBLIC) as $method){ if(!$method->isStatic() and $method->getDeclaringClass()->implementsInterface(Listener::class)){ $tags = Utils::parseDocComment((string) $method->getDocComment()); - if(isset($tags["notHandler"])){ + if(isset($tags[ListenerMethodTags::NOT_HANDLER])){ continue; } @@ -476,14 +477,14 @@ class PluginManager{ if($handlerClosure === null) throw new AssumptionFailedError("This should never happen"); try{ - $priority = isset($tags["priority"]) ? EventPriority::fromString($tags["priority"]) : EventPriority::NORMAL; + $priority = isset($tags[ListenerMethodTags::PRIORITY]) ? EventPriority::fromString($tags[ListenerMethodTags::PRIORITY]) : EventPriority::NORMAL; }catch(\InvalidArgumentException $e){ - throw new PluginException("Event handler " . Utils::getNiceClosureName($handlerClosure) . "() declares invalid/unknown priority \"" . $tags["priority"] . "\""); + throw new PluginException("Event handler " . Utils::getNiceClosureName($handlerClosure) . "() declares invalid/unknown priority \"" . $tags[ListenerMethodTags::PRIORITY] . "\""); } $handleCancelled = false; - if(isset($tags["handleCancelled"])){ - switch(strtolower($tags["handleCancelled"])){ + if(isset($tags[ListenerMethodTags::HANDLE_CANCELLED])){ + switch(strtolower($tags[ListenerMethodTags::HANDLE_CANCELLED])){ case "true": case "": $handleCancelled = true; @@ -491,7 +492,7 @@ class PluginManager{ case "false": break; default: - throw new PluginException("Event handler " . Utils::getNiceClosureName($handlerClosure) . "() declares invalid @handleCancelled value \"" . $tags["handleCancelled"] . "\""); + throw new PluginException("Event handler " . Utils::getNiceClosureName($handlerClosure) . "() declares invalid @" . ListenerMethodTags::HANDLE_CANCELLED . " value \"" . $tags[ListenerMethodTags::HANDLE_CANCELLED] . "\""); } }