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 { /** @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; } } }