Files
kiri-core/kiri-gii/GiiCommand.php
T

77 lines
1.7 KiB
PHP
Raw Normal View History

2021-09-02 11:26:11 +08:00
<?php
declare(strict_types=1);
namespace Gii;
use Exception;
use Kiri\Abstracts\Config;
use Kiri\Exception\ConfigException;
use Kiri\Kiri;
use Symfony\Component\Console\Command\Command;
2021-09-29 10:29:31 +08:00
use Symfony\Component\Console\Input\InputArgument;
2021-09-02 11:26:11 +08:00
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Class Command
* @package Http
*/
class GiiCommand extends Command
{
public string $command = 'sw:gii';
public string $description = './snowflake sw:gii make=model|controller|task|interceptor|limits|middleware name=xxxx';
2021-09-02 11:58:53 +08:00
/**
*
*/
protected function configure()
{
$this->setName('sw:gii')
2021-09-29 10:59:55 +08:00
->addArgument('action', InputArgument::REQUIRED)
2021-10-28 11:21:56 +08:00
->addArgument('name', InputArgument::OPTIONAL)
2021-10-28 11:26:58 +08:00
->addArgument('databases', InputArgument::OPTIONAL)
2021-09-02 11:58:53 +08:00
->setDescription('./snowflake sw:gii make=model|controller|task|interceptor|limits|middleware name=xxxx');
}
2021-09-02 11:26:11 +08:00
/**
* @param InputInterface $input
* @param OutputInterface $output
2021-10-28 11:09:14 +08:00
* @return int
2021-09-02 11:26:11 +08:00
* @throws ConfigException
2021-10-28 11:26:58 +08:00
* @throws Exception
2021-09-02 11:26:11 +08:00
*/
2021-09-29 10:59:55 +08:00
public function execute(InputInterface $input, OutputInterface $output): int
2021-09-02 11:26:11 +08:00
{
/** @var Gii $gii */
$gii = Kiri::app()->get('gii');
$connections = Kiri::app()->get('db');
2021-10-28 11:32:29 +08:00
if (($db = $input->getArgument('databases')) != null) {
$gii->run($connections->get($db), $input);
2021-10-28 11:26:58 +08:00
return 1;
}
$action = $input->getArgument('action');
if (!in_array($action, ['model', 'controller'])) {
$gii->run(null, $input);
return 1;
}
2021-09-02 11:26:11 +08:00
$array = [];
2021-09-29 10:30:36 +08:00
foreach (Config::get('databases.connections') as $key => $connection) {
2021-09-02 11:26:11 +08:00
$array[$key] = $gii->run($connections->get($key), $input);
}
2021-09-29 10:59:55 +08:00
$output->writeln(json_encode($array, JSON_UNESCAPED_UNICODE));
return 1;
2021-09-02 11:26:11 +08:00
}
}