From 67c2e6eab588cabd1df617cac486617e4b0460da Mon Sep 17 00:00:00 2001 From: Angger Pradana Date: Tue, 4 Jun 2024 12:08:06 +0700 Subject: [PATCH] refactor: use set and call (remove `DI\autowire`) (#335) --- src/System/Integrate/Console/Karnel.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/System/Integrate/Console/Karnel.php b/src/System/Integrate/Console/Karnel.php index a87bd164..8d25c1c4 100644 --- a/src/System/Integrate/Console/Karnel.php +++ b/src/System/Integrate/Console/Karnel.php @@ -57,15 +57,12 @@ public function handle($arguments) $commands = array_merge($commands, $cmd->patterns(), $cmd->cmd()); if ($cmd->isMatch($baseArgs)) { - $this->app->set( - $cmd->class(), - \DI\autowire($cmd->class())->constructor($arguments, $cmd->defaultOption()) - ); + $class = $cmd->class(); + $this->app->set($class, fn () => new $class($arguments, $cmd->defaultOption())); - $service = $this->app->get($cmd->class()); - $this->app->call($cmd->call()); + $call = $this->app->call($cmd->call()); - return $this->exit_code = $service->exit ?? 0; + return $this->exit_code = (is_int($call) ? $call : 0); } }