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
+44 -49
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;
@@ -20,59 +19,55 @@ use Symfony\Component\Console\Output\OutputInterface;
class GiiCommand extends Command 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');
}
/** /**
* * @param InputInterface $input
*/ * @param OutputInterface $output
protected function configure() * @return int
{ * @throws Exception
$this->service = Kiri::getDi()->get(LocalService::class); */
$this->setName('sw:gii') public function execute(InputInterface $input, OutputInterface $output): int
->addOption('make', 'm', InputArgument::OPTIONAL) {
->addOption('table', 't', InputArgument::OPTIONAL) try {
->addOption('database', 'd', InputArgument::OPTIONAL) $database = Kiri::getDi()->get(DatabasesProviders::class);
->setDescription('php kiri.php sw:gii --table u_user --database users --make model');
}
/** @var Gii $gii */
/** $gii = Kiri::getDi()->get(Gii::class);
* @param InputInterface $input if (($db = $input->getOption('database')) != null) {
* @param OutputInterface $output return count($gii->run($database->get($db), $input));
* @return int }
* @throws Exception $action = $input->getOption('make');
*/ if (!in_array($action, ['model', 'controller'])) {
public function execute(InputInterface $input, OutputInterface $output): int return count($gii->run(null, $input));
{ }
try { $array = [];
/** @var Gii $gii */ foreach (\config('databases.connections') as $key => $connection) {
$gii = $this->service->get('gii'); $array[$key] = $gii->run($database->get($key), $input);
if (($db = $input->getOption('database')) != null) { }
$gii->run($this->service->get($db), $input); $output->writeln(json_encode($array, JSON_UNESCAPED_UNICODE));
} else { return 0;
$action = $input->getOption('make'); } catch (\Throwable $throwable) {
if (!in_array($action, ['model', 'controller'])) { $output->writeln(throwable($throwable));
$gii->run(null, $input); return 1;
} 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;
}
}
} }
+10 -14
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;
@@ -19,17 +18,14 @@ class GiiProviders extends Providers
{ {
/** /**
* @param LocalService $application * @return void
* @return void * @throws ContainerExceptionInterface
* @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface
* @throws NotFoundExceptionInterface */
*/ public function onImport(): void
public function onImport(LocalService $application): void {
{ $console = $this->container->get(Application::class);
$application->set('gii', ['class' => Gii::class]); $console->add($this->container->get(GiiCommand::class));
}
$console = $this->container->get(Application::class);
$console->add($this->container->get(GiiCommand::class));
}
} }