From 18df76f6504174ef64430ba08fa4aeeae1d77fb8 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sat, 31 Dec 2022 19:12:29 +0800 Subject: [PATCH] fix AnnotationHandler return callback not working for BotCommand --- src/ZM/Annotation/AnnotationHandler.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/ZM/Annotation/AnnotationHandler.php b/src/ZM/Annotation/AnnotationHandler.php index f65ade0a..62591774 100644 --- a/src/ZM/Annotation/AnnotationHandler.php +++ b/src/ZM/Annotation/AnnotationHandler.php @@ -94,15 +94,6 @@ class AnnotationHandler foreach ((AnnotationMap::$_list[$this->annotation_class] ?? []) as $v) { // 调用单个注解 $this->handle($v, $this->rule_callback, ...$params); - // 执行完毕后检查状态,如果状态是规则判断或中间件before不通过,则重置状态后继续执行别的注解函数 - if ($this->status == self::STATUS_BEFORE_FAILED || $this->status == self::STATUS_RULE_FAILED) { - $this->status = self::STATUS_NORMAL; - continue; - } - // 如果执行完毕,且设置了返回值后续逻辑的回调函数,那么就调用返回值回调的逻辑 - if (is_callable($this->return_callback) && $this->status === self::STATUS_NORMAL) { - ($this->return_callback)($this->return_val); - } } } catch (InterruptException $e) { // InterruptException 用于中断,这里必须 catch,并标记状态 @@ -140,6 +131,15 @@ class AnnotationHandler } try { $this->return_val = middleware()->process($callback, ...$args); + // 执行完毕后检查状态,如果状态是规则判断或中间件before不通过,则重置状态后继续执行别的注解函数 + if ($this->status == self::STATUS_BEFORE_FAILED || $this->status == self::STATUS_RULE_FAILED) { + $this->status = self::STATUS_NORMAL; + return false; + } + // 如果执行完毕,且设置了返回值后续逻辑的回调函数,那么就调用返回值回调的逻辑 + if (is_callable($this->return_callback) && $this->status === self::STATUS_NORMAL) { + ($this->return_callback)($this->return_val); + } } catch (InterruptException $e) { // 这里直接抛出这个异常的目的就是给上层handleAll()捕获 throw $e;