From 843f9858bca60ad5cef266bdbbc75825409d922b Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 5 Nov 2024 11:17:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E4=BA=8B=E4=BB=B6=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E6=94=AF=E6=8C=81=E4=BE=9D=E8=B5=96=E6=B3=A8=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Model.php | 8 ++++++-- src/model/concern/ModelEvent.php | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Model.php b/src/Model.php index d123ed6f..487e6984 100644 --- a/src/Model.php +++ b/src/Model.php @@ -235,13 +235,17 @@ public static function setInvoker(callable $callable): void */ public function invoke($method, array $vars = []) { + if (is_string($method)) { + $method = [$this, $method]; + } + if (self::$invoker) { $call = self::$invoker; - return $call($method instanceof Closure ? $method : Closure::fromCallable([$this, $method]), $vars); + return $call($method instanceof Closure ? $method : Closure::fromCallable($method), $vars); } - return call_user_func_array($method instanceof Closure ? $method : [$this, $method], $vars); + return call_user_func_array($method, $vars); } /** diff --git a/src/model/concern/ModelEvent.php b/src/model/concern/ModelEvent.php index 136537e7..ae0b1975 100644 --- a/src/model/concern/ModelEvent.php +++ b/src/model/concern/ModelEvent.php @@ -93,7 +93,7 @@ protected function trigger(string $event): bool } if (method_exists($observer, $call)) { - $result = call_user_func([$observer, $call], $this); + $result = $this->invoke([$observer, $call], [$this]); } elseif (is_object(self::$event) && method_exists(self::$event, 'trigger')) { $result = self::$event->trigger(static::class . '.' . $event, $this); $result = empty($result) ? true : end($result);