From 4740eb1ca9c9b5fbe84d04d8038ea2071134fc05 Mon Sep 17 00:00:00 2001 From: whwyy Date: Thu, 30 Nov 2023 17:02:21 +0800 Subject: [PATCH] eee --- GiiCommand.php | 93 +++++++++++++++++++++++------------------------- GiiProviders.php | 24 ++++++------- 2 files changed, 54 insertions(+), 63 deletions(-) diff --git a/GiiCommand.php b/GiiCommand.php index d145ddd..0e9e8ae 100644 --- a/GiiCommand.php +++ b/GiiCommand.php @@ -4,10 +4,9 @@ declare(strict_types=1); namespace Gii; +use Database\DatabasesProviders; use Exception; use Kiri; -use Kiri\Di\LocalService; -use Kiri\Exception\ConfigException; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -20,59 +19,55 @@ use Symfony\Component\Console\Output\OutputInterface; class GiiCommand extends Command { - public string $command = 'sw:gii'; + public string $command = 'sw:gii'; - public string $description = './snowflake sw:gii make=model|controller|task|interceptor|limits|middleware name=xxxx'; + public string $description = './snowflake sw:gii make=model|controller|task|interceptor|limits|middleware name=xxxx'; - private LocalService $service; + /** + * + */ + protected function configure() + { + $this->setName('sw:gii') + ->addOption('make', 'm', InputArgument::OPTIONAL) + ->addOption('table', 't', InputArgument::OPTIONAL) + ->addOption('database', 'd', InputArgument::OPTIONAL) + ->setDescription('php kiri.php sw:gii --table u_user --database users --make model'); + } - /** - * - */ - protected function configure() - { - $this->service = Kiri::getDi()->get(LocalService::class); - $this->setName('sw:gii') - ->addOption('make', 'm', InputArgument::OPTIONAL) - ->addOption('table', 't', InputArgument::OPTIONAL) - ->addOption('database', 'd', InputArgument::OPTIONAL) - ->setDescription('php kiri.php sw:gii --table u_user --database users --make model'); - } + /** + * @param InputInterface $input + * @param OutputInterface $output + * @return int + * @throws Exception + */ + public function execute(InputInterface $input, OutputInterface $output): int + { + try { + $database = Kiri::getDi()->get(DatabasesProviders::class); - - /** - * @param InputInterface $input - * @param OutputInterface $output - * @return int - * @throws Exception - */ - public function execute(InputInterface $input, OutputInterface $output): int - { - try { - /** @var Gii $gii */ - $gii = $this->service->get('gii'); - if (($db = $input->getOption('database')) != null) { - $gii->run($this->service->get($db), $input); - } else { - $action = $input->getOption('make'); - if (!in_array($action, ['model', 'controller'])) { - $gii->run(null, $input); - } else { - $array = []; - foreach (\config('databases.connections') as $key => $connection) { - $array[$key] = $gii->run($this->service->get($key), $input); - } - $output->writeln(json_encode($array, JSON_UNESCAPED_UNICODE)); - } - } - } catch (\Throwable $throwable) { - $output->writeln(throwable($throwable)); - } finally { - return 1; - } - } + /** @var Gii $gii */ + $gii = Kiri::getDi()->get(Gii::class); + if (($db = $input->getOption('database')) != null) { + return count($gii->run($database->get($db), $input)); + } + $action = $input->getOption('make'); + if (!in_array($action, ['model', 'controller'])) { + return count($gii->run(null, $input)); + } + $array = []; + foreach (\config('databases.connections') as $key => $connection) { + $array[$key] = $gii->run($database->get($key), $input); + } + $output->writeln(json_encode($array, JSON_UNESCAPED_UNICODE)); + return 0; + } catch (\Throwable $throwable) { + $output->writeln(throwable($throwable)); + return 1; + } + } } diff --git a/GiiProviders.php b/GiiProviders.php index 0dad79b..c4fb758 100644 --- a/GiiProviders.php +++ b/GiiProviders.php @@ -6,7 +6,6 @@ namespace Gii; use Kiri\Abstracts\Providers; -use Kiri\Di\LocalService; use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; use Symfony\Component\Console\Application; @@ -19,17 +18,14 @@ class GiiProviders extends Providers { - /** - * @param LocalService $application - * @return void - * @throws ContainerExceptionInterface - * @throws NotFoundExceptionInterface - */ - public function onImport(LocalService $application): void - { - $application->set('gii', ['class' => Gii::class]); - - $console = $this->container->get(Application::class); - $console->add($this->container->get(GiiCommand::class)); - } + /** + * @return void + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + public function onImport(): void + { + $console = $this->container->get(Application::class); + $console->add($this->container->get(GiiCommand::class)); + } }