diff --git a/Annotation/Event.php b/Annotation/Event.php index 36a8b983..e14edae1 100644 --- a/Annotation/Event.php +++ b/Annotation/Event.php @@ -35,7 +35,10 @@ use Kiri\Events\EventProvider; public function execute(mixed $class, mixed $method = null): bool { $pro = di(EventProvider::class); - $pro->on($this->name, [di($class), $method]); + if (is_string($class)) { + $class = di($class); + } + $pro->on($this->name, [$class, $method]); return true; } diff --git a/HttpServer/Route/Router.php b/HttpServer/Route/Router.php index 77b80fe5..3bddaf97 100644 --- a/HttpServer/Route/Router.php +++ b/HttpServer/Route/Router.php @@ -554,14 +554,13 @@ class Router extends HttpService implements RouterInterface $di = Kiri::getDi(); foreach ($classes as $class) { - $instance = $di->get($class); $methods = $di->getMethodAttribute($class); foreach ($methods as $method => $attribute) { if (empty($attribute)) { continue; } foreach ($attribute as $item) { - $item->execute($instance, $method); + $item->execute($class, $method); } } } diff --git a/Server/Worker/OnServerWorker.php b/Server/Worker/OnServerWorker.php index 803f285f..386931ea 100644 --- a/Server/Worker/OnServerWorker.php +++ b/Server/Worker/OnServerWorker.php @@ -62,7 +62,6 @@ class OnServerWorker extends \Server\Abstracts\Server /** * @param Annotation $annotation - * @throws NotFindClassException * @throws ReflectionException * @throws Exception */ diff --git a/function.php b/function.php index ce1aa1a4..8e77659d 100644 --- a/function.php +++ b/function.php @@ -123,9 +123,8 @@ if (!function_exists('injectRuntime')) { $fileLists = Kiri::getAnnotation()->runtime($path, $exclude); $di = Kiri::getDi(); foreach ($fileLists as $class) { - $instance = $di->get($class); foreach ($di->getTargetNote($class) as $value) { - $value->execute($instance); + $value->execute($class); } $methods = $di->getMethodAttribute($class); foreach ($methods as $method => $attribute) { @@ -133,7 +132,7 @@ if (!function_exists('injectRuntime')) { continue; } foreach ($attribute as $item) { - $item->execute($instance, $method); + $item->execute($class, $method); } } }