This commit is contained in:
2023-11-30 17:02:21 +08:00
parent 314fadca7f
commit 4740eb1ca9
2 changed files with 54 additions and 63 deletions
+10 -15
View File
@@ -4,10 +4,9 @@ declare(strict_types=1);
namespace Gii; namespace Gii;
use Database\DatabasesProviders;
use Exception; use Exception;
use Kiri; use Kiri;
use Kiri\Di\LocalService;
use Kiri\Exception\ConfigException;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
@@ -26,15 +25,11 @@ class GiiCommand extends Command
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() protected function configure()
{ {
$this->service = Kiri::getDi()->get(LocalService::class);
$this->setName('sw:gii') $this->setName('sw:gii')
->addOption('make', 'm', InputArgument::OPTIONAL) ->addOption('make', 'm', InputArgument::OPTIONAL)
->addOption('table', 't', InputArgument::OPTIONAL) ->addOption('table', 't', InputArgument::OPTIONAL)
@@ -52,25 +47,25 @@ class GiiCommand extends Command
public function execute(InputInterface $input, OutputInterface $output): int public function execute(InputInterface $input, OutputInterface $output): int
{ {
try { try {
$database = Kiri::getDi()->get(DatabasesProviders::class);
/** @var Gii $gii */ /** @var Gii $gii */
$gii = $this->service->get('gii'); $gii = Kiri::getDi()->get(Gii::class);
if (($db = $input->getOption('database')) != null) { if (($db = $input->getOption('database')) != null) {
$gii->run($this->service->get($db), $input); return count($gii->run($database->get($db), $input));
} else { }
$action = $input->getOption('make'); $action = $input->getOption('make');
if (!in_array($action, ['model', 'controller'])) { if (!in_array($action, ['model', 'controller'])) {
$gii->run(null, $input); return count($gii->run(null, $input));
} else { }
$array = []; $array = [];
foreach (\config('databases.connections') as $key => $connection) { foreach (\config('databases.connections') as $key => $connection) {
$array[$key] = $gii->run($this->service->get($key), $input); $array[$key] = $gii->run($database->get($key), $input);
} }
$output->writeln(json_encode($array, JSON_UNESCAPED_UNICODE)); $output->writeln(json_encode($array, JSON_UNESCAPED_UNICODE));
} return 0;
}
} catch (\Throwable $throwable) { } catch (\Throwable $throwable) {
$output->writeln(throwable($throwable)); $output->writeln(throwable($throwable));
} finally {
return 1; return 1;
} }
} }
+1 -5
View File
@@ -6,7 +6,6 @@ namespace Gii;
use Kiri\Abstracts\Providers; use Kiri\Abstracts\Providers;
use Kiri\Di\LocalService;
use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface; use Psr\Container\NotFoundExceptionInterface;
use Symfony\Component\Console\Application; use Symfony\Component\Console\Application;
@@ -20,15 +19,12 @@ class GiiProviders extends Providers
/** /**
* @param LocalService $application
* @return void * @return void
* @throws ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface * @throws NotFoundExceptionInterface
*/ */
public function onImport(LocalService $application): void public function onImport(): void
{ {
$application->set('gii', ['class' => Gii::class]);
$console = $this->container->get(Application::class); $console = $this->container->get(Application::class);
$console->add($this->container->get(GiiCommand::class)); $console->add($this->container->get(GiiCommand::class));
} }