diff --git a/http-helper/Command.php b/http-helper/Command.php index d20dafd3..285bff12 100644 --- a/http-helper/Command.php +++ b/http-helper/Command.php @@ -16,6 +16,8 @@ use Server\Events\OnBeforeWorkerStart; use Server\Events\OnWorkerStart; use Server\Worker\OnServerWorker; use Server\Worker\OnWorkerStart as WorkerDispatch; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; /** * Class Command @@ -24,11 +26,6 @@ use Server\Worker\OnWorkerStart as WorkerDispatch; class Command extends \Symfony\Component\Console\Command\Command { - public string $command = 'sw:server'; - - - public string $description = 'server start|stop|reload|restart'; - const ACTIONS = ['start', 'stop', 'restart']; @@ -45,30 +42,33 @@ class Command extends \Symfony\Component\Console\Command\Command */ protected function configure() { - $this->setName('swoole') + $this->setName('sw:server') ->setDescription('server start|stop|reload|restart'); } /** - * @param Input $dtl + * @param InputInterface $input + * @param OutputInterface $output * @return string - * @throws Exception * @throws ConfigException + * @throws NotFindClassException + * @throws ReflectionException + * @throws Exception */ - public function onHandler(Input $dtl): string + public function execute(InputInterface $input, OutputInterface $output): string { $manager = Kiri::app()->getServer(); - $manager->setDaemon($dtl->get('daemon', 0)); - if (!in_array($dtl->get('action'), self::ACTIONS)) { - return 'I don\'t know what I want to do.'; + $manager->setDaemon($input->getArgument('daemon')); + if (!in_array($input->getArgument('action'), self::ACTIONS)) { + return $output->write('I don\'t know what I want to do.'); } - if ($manager->isRunner() && $dtl->get('action') == 'start') { - return 'Service is running. Please use restart.'; + if ($manager->isRunner() && $input->getArgument('action') == 'start') { + return $output->write('Service is running. Please use restart.'); } $manager->shutdown(); - if ($dtl->get('action') == 'stop') { - return 'shutdown success.'; + if ($input->getArgument('action') == 'stop') { + return $output->write('shutdown success'); } return $this->generate_runtime_builder($manager); } diff --git a/http-helper/ServerProviders.php b/http-helper/ServerProviders.php index 3b4243f3..a3cc8376 100644 --- a/http-helper/ServerProviders.php +++ b/http-helper/ServerProviders.php @@ -4,10 +4,10 @@ declare(strict_types=1); namespace Http; -use Console\Console; use Exception; use Kiri\Abstracts\Providers; use Kiri\Application; +use Kiri\Kiri; /** * Class DatabasesProviders @@ -25,8 +25,10 @@ class ServerProviders extends Providers { $application->set('server', ['class' => Server::class]); - /** @var Console $console */ - $console = $application->get('console'); - $console->register(Command::class); + $container = Kiri::getDi(); + + $console = $container->get(\Symfony\Component\Console\Application::class); + $console->add($container->get(Command::class)); + } } diff --git a/kiri-gii/Command.php b/kiri-gii/Command.php deleted file mode 100644 index 464b6f59..00000000 --- a/kiri-gii/Command.php +++ /dev/null @@ -1,48 +0,0 @@ -get('gii'); - - $connections = Kiri::app()->get('db'); - if ($dtl->exists('databases')) { - return $gii->run($connections->get($dtl->get('databases')), $dtl); - } - - $array = []; - foreach (Config::get('databases') as $key => $connection) { - $array[$key] = $gii->run($connections->get($key), $dtl); - } - return $array; - } - -} diff --git a/kiri-gii/Gii.php b/kiri-gii/Gii.php index 6f269f25..56550e6c 100644 --- a/kiri-gii/Gii.php +++ b/kiri-gii/Gii.php @@ -12,10 +12,10 @@ namespace Gii; use Database\Connection; use Database\Db; use Exception; -use Kiri\Abstracts\Input; use Kiri\Exception\ComponentException; use Kiri\Exception\ConfigException; use Kiri\Kiri; +use Symfony\Component\Console\Input\InputInterface; /** * Class gii @@ -29,8 +29,7 @@ class Gii /** @var Connection */ private Connection $db; - /** @var Input */ - private Input $input; + private InputInterface $input; public string $modelPath = APP_PATH . 'app/Models/'; public string $modelNamespace = 'App\\Models\\'; @@ -49,32 +48,31 @@ class Gii /** * @param Connection|null $db * - * @param $input + * @param InputInterface $input * @return array * @throws ComponentException * @throws ConfigException - * @throws Exception */ - public function run(?Connection $db, $input): array + public function run(?Connection $db, InputInterface $input): array { return $this->gen($input, $db); } /** - * @param $input + * @param InputInterface $input * @param $db * @return array * @throws ComponentException * @throws ConfigException * @throws Exception */ - public function gen($input, $db): array + public function gen(InputInterface $input, $db): array { $this->input = $input; if (!empty($db)) $this->db = $db; - $make = $this->input->get('make', null); + $make = $this->input->getArgument('make'); if (empty($make)) { throw new Exception('构建类型不能为空~'); } @@ -83,14 +81,6 @@ class Gii $task = new GiiTask(); $task->setInput($this->input); return $task->generate(); - case 'interceptor': - $task = new GiiInterceptor(); - $task->setInput($this->input); - return $task->generate(); - case 'limits': - $task = new GiiLimits(); - $task->setInput($this->input); - return $task->generate(); case 'middleware': $task = new GiiMiddleware(); $task->setInput($this->input); @@ -114,7 +104,6 @@ class Gii * @param $input * @return array * @throws ComponentException - * @throws ConfigException * @throws Exception */ private function getModel($make, $input): array @@ -122,7 +111,7 @@ class Gii if ($this->db instanceof Connection) { return $this->makeByDatabases($make, $input); } - $db = $this->input->get('databases', 'db'); + $db = $this->input->getArgument('databases'); $this->db = Kiri::app()->get('db')->get($db); return $this->makeByDatabases($make, $input); @@ -131,16 +120,15 @@ class Gii /** * @param $make - * @param $input + * @param InputInterface $input * @return array - * @throws ComponentException * @throws Exception */ - private function makeByDatabases($make, $input): array + private function makeByDatabases($make, InputInterface $input): array { $redis = Kiri::app()->getRedis(); - if (!empty($input->get('name'))) { - $this->tableName = $input->get('name'); + if (!empty($input->getArgument('name'))) { + $this->tableName = $input->getArgument('name'); $redis->del('column:' . $this->tableName); } return match ($make) { @@ -190,7 +178,7 @@ class Gii $controller->setModelPath($this->modelPath); $controller->setModelNamespace($this->modelNamespace); $controller->setInput($this->input); - $controller->setModule($this->input->get('module', null)); + $controller->setModule($this->input->getArgument('module')); $controller->setControllerPath($this->controllerPath); $controller->setControllerNamespace($this->controllerNamespace); return $controller->generate(); @@ -209,7 +197,7 @@ class Gii $controller->setInput($this->input); $controller->setModelNamespace($this->modelNamespace); $controller->setControllerPath($this->controllerPath); - $controller->setModule($this->input->get('module', null)); + $controller->setModule($this->input->getArgument('module')); $controller->setControllerNamespace($this->controllerNamespace); return $controller->generate(); } diff --git a/kiri-gii/GiiBase.php b/kiri-gii/GiiBase.php index 4bcf9a84..a720c06e 100644 --- a/kiri-gii/GiiBase.php +++ b/kiri-gii/GiiBase.php @@ -13,6 +13,7 @@ use ReflectionClass; use ReflectionException; use Kiri\Abstracts\Input; use Kiri\Core\Json; +use Symfony\Component\Console\Input\InputInterface; /** * Class GiiBase @@ -24,8 +25,7 @@ abstract class GiiBase public array $fileList = []; - /** @var Input */ - protected Input $input; + protected InputInterface $input; public string $modelPath = APP_PATH . 'app/Models/'; public string $modelNamespace = 'App\Models\\'; @@ -92,9 +92,9 @@ abstract class GiiBase /** - * @param Input $input + * @param InputInterface $input */ - public function setInput(Input $input) + public function setInput(InputInterface $input) { $this->input = $input; } diff --git a/kiri-gii/GiiCommand.php b/kiri-gii/GiiCommand.php new file mode 100644 index 00000000..fc53dd8d --- /dev/null +++ b/kiri-gii/GiiCommand.php @@ -0,0 +1,58 @@ +get('gii'); + + $connections = Kiri::app()->get('db'); + if ($input->getArgument('databases')) { + return $gii->run($connections->get($input->getArgument('databases')), $input); + } + + $array = []; + foreach (Config::get('databases') as $key => $connection) { + $array[$key] = $gii->run($connections->get($key), $input); + } + return $array; + } + +} diff --git a/kiri-gii/GiiMiddleware.php b/kiri-gii/GiiMiddleware.php index deebd931..bd65a57e 100644 --- a/kiri-gii/GiiMiddleware.php +++ b/kiri-gii/GiiMiddleware.php @@ -23,7 +23,7 @@ class GiiMiddleware extends GiiBase public function generate(): array { - $managerName = $this->input->get('name', null); + $managerName = $this->input->getArgument('name'); if (empty($managerName)) { throw new Exception('文件名称不能为空~'); } diff --git a/kiri-gii/GiiProviders.php b/kiri-gii/GiiProviders.php index 4d81add4..f213fbc5 100644 --- a/kiri-gii/GiiProviders.php +++ b/kiri-gii/GiiProviders.php @@ -5,10 +5,10 @@ declare(strict_types=1); namespace Gii; -use Console\Console; use Exception; use Kiri\Abstracts\Providers; use Kiri\Application; +use Kiri\Kiri; /** * Class DatabasesProviders @@ -26,8 +26,9 @@ class GiiProviders extends Providers { $application->set('gii', ['class' => Gii::class]); - /** @var Console $console */ - $console = $application->get('console'); - $console->register(Command::class); + $container = Kiri::getDi(); + + $console = $container->get(\Symfony\Component\Console\Application::class); + $console->add($container->get(GiiCommand::class)); } } diff --git a/kiri-gii/GiiRpcClient.php b/kiri-gii/GiiRpcClient.php index fab66d85..b8998a1d 100644 --- a/kiri-gii/GiiRpcClient.php +++ b/kiri-gii/GiiRpcClient.php @@ -21,15 +21,15 @@ class GiiRpcClient extends GiiBase public function generate(): array { - $managerName = $this->input->get('name', null); + $managerName = $this->input->getArgument('name', null); if (empty($managerName)) { throw new Exception('文件名称不能为空~'); } - $service = $this->input->get('service', strtolower($managerName)); + $service = $this->input->getArgument('service', strtolower($managerName)); - $port = $this->input->get('port', 443); - $mode = $this->input->get('mode', 'SWOOLE_SOCK_TCP'); + $port = $this->input->getArgument('port', 443); + $mode = $this->input->getArgument('mode', 'SWOOLE_SOCK_TCP'); $html = 'input->get('name', null); + $managerName = $this->input->getArgument('name', null); if (empty($managerName)) { throw new Exception('文件名称不能为空~'); } - $port = $this->input->get('port', 443); + $port = $this->input->getArgument('port', 443); $html = 'input->get('name', null); + $managerName = $this->input->getArgument('name', null); if (empty($managerName)) { throw new Exception('文件名称不能为空~'); }