From 81365173d26ef8cbf48ca500003bf37a97266608 Mon Sep 17 00:00:00 2001 From: jerry Date: Sun, 20 Dec 2020 18:08:34 +0800 Subject: [PATCH] update to 2.0.0-b6 version add interrupt return_value to InterruptException --- src/ZM/Event/EventDispatcher.php | 9 +++++---- src/ZM/Exception/InterruptException.php | 7 +++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/ZM/Event/EventDispatcher.php b/src/ZM/Event/EventDispatcher.php index 8bbd3654..0c5e8489 100644 --- a/src/ZM/Event/EventDispatcher.php +++ b/src/ZM/Event/EventDispatcher.php @@ -29,10 +29,11 @@ class EventDispatcher private $eid = 0; /** + * @param null $return_var * @throws InterruptException */ - public static function interrupt() { - throw new InterruptException('interrupt'); + public static function interrupt($return_var = null) { + throw new InterruptException($return_var); } public static function enableEventTrace($event_class) { @@ -85,7 +86,7 @@ class EventDispatcher } return true; } catch (InterruptException $e) { - return null; + return $e->return_var; } catch (AnnotationException $e) { return false; } @@ -95,9 +96,9 @@ class EventDispatcher * @param AnnotationBase|null $v * @param null $rule_func * @param mixed ...$params - * @return bool * @throws AnnotationException * @throws InterruptException + * @return mixed */ public function dispatchEvent(?AnnotationBase $v, $rule_func = null, ...$params) { $q_c = $v->class; diff --git a/src/ZM/Exception/InterruptException.php b/src/ZM/Exception/InterruptException.php index b5b5a5f8..cb97d954 100644 --- a/src/ZM/Exception/InterruptException.php +++ b/src/ZM/Exception/InterruptException.php @@ -4,7 +4,14 @@ namespace ZM\Exception; +use Throwable; + class InterruptException extends ZMException { + public $return_var = null; + public function __construct($return_var = null, $message = "", $code = 0, Throwable $previous = null) { + parent::__construct($message, $code, $previous); + $this->return_var = $return_var; + } }