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;
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;
@@ -26,15 +25,11 @@ class GiiCommand extends Command
public string $description = './snowflake sw:gii make=model|controller|task|interceptor|limits|middleware name=xxxx';
private LocalService $service;
/**
*
*/
protected function configure()
{
$this->service = Kiri::getDi()->get(LocalService::class);
$this->setName('sw:gii')
->addOption('make', 'm', InputArgument::OPTIONAL)
->addOption('table', 't', InputArgument::OPTIONAL)
@@ -52,25 +47,25 @@ class GiiCommand extends Command
public function execute(InputInterface $input, OutputInterface $output): int
{
try {
$database = Kiri::getDi()->get(DatabasesProviders::class);
/** @var Gii $gii */
$gii = $this->service->get('gii');
$gii = Kiri::getDi()->get(Gii::class);
if (($db = $input->getOption('database')) != null) {
$gii->run($this->service->get($db), $input);
} else {
return count($gii->run($database->get($db), $input));
}
$action = $input->getOption('make');
if (!in_array($action, ['model', 'controller'])) {
$gii->run(null, $input);
} else {
return count($gii->run(null, $input));
}
$array = [];
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));
}
}
return 0;
} catch (\Throwable $throwable) {
$output->writeln(throwable($throwable));
} finally {
return 1;
}
}
+1 -5
View File
@@ -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;
@@ -20,15 +19,12 @@ class GiiProviders extends Providers
/**
* @param LocalService $application
* @return void
* @throws ContainerExceptionInterface
* @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->add($this->container->get(GiiCommand::class));
}