diff --git a/HttpServer/Command.php b/HttpServer/Command.php index 71453dad..d2623664 100644 --- a/HttpServer/Command.php +++ b/HttpServer/Command.php @@ -53,7 +53,7 @@ class Command extends \Console\Command return 'shutdown success.'; } - listen(Event::SERVER_BEFORE_START, [$this, 'scan_system_annotation']); + $this->scan_system_annotation(); return $manager->start(); } diff --git a/System/Event.php b/System/Event.php index 05bbb813..f06aa3aa 100644 --- a/System/Event.php +++ b/System/Event.php @@ -187,28 +187,32 @@ class Event extends BaseObject * @param null $parameter * @param null $handler * @param false $is_remove - * @return mixed + * @return bool */ - public function trigger($name, $parameter = null, $handler = null, $is_remove = false): mixed + public function trigger($name, $parameter = null, $handler = null, $is_remove = false): bool { - if (!$this->exists($name)) { - return false; - } - if (!empty($handler) && $this->exists($name, $handler)) { - $events = [$this->get($name, $handler)]; - } else { - $events = $this->_events[$name]; - } - foreach ($events as $index => $event) { - $meta = $this->mergeParams($event[1], $parameter); - if (call_user_func($event[0], ...$meta) === false) { + try { + if (!$this->exists($name)) { return false; } + if (!empty($handler) && $this->exists($name, $handler)) { + $events = [$this->get($name, $handler)]; + } else { + $events = $this->_events[$name]; + } + foreach ($events as $index => $event) { + $meta = $this->mergeParams($event[1], $parameter); + if (call_user_func($event[0], ...$meta) === false) { + return false; + } + } + if ($is_remove) { + $this->offName($name); + } + return true; + } catch (\Throwable $throwable) { + return false; } - if ($is_remove) { - $this->offName($name); - } - return true; }