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);