This commit is contained in:
2021-09-02 11:26:11 +08:00
parent 4e2bb41358
commit 428987406c
11 changed files with 111 additions and 110 deletions
+16 -16
View File
@@ -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);
}
+6 -4
View File
@@ -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));
}
}
-48
View File
@@ -1,48 +0,0 @@
<?php
declare(strict_types=1);
namespace Gii;
use Exception;
use Kiri\Abstracts\Config;
use Kiri\Abstracts\Input;
use Kiri\Exception\ConfigException;
use Kiri\Kiri;
/**
* Class Command
* @package Http
*/
class Command extends \Console\Command
{
public string $command = 'sw:gii';
public string $description = './snowflake sw:gii make=model|controller|task|interceptor|limits|middleware name=xxxx';
/**
* @param Input $dtl
* @return array
* @throws Exception
*/
public function onHandler(Input $dtl): array
{
/** @var Gii $gii */
$gii = Kiri::app()->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;
}
}
+14 -26
View File
@@ -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();
}
+4 -4
View File
@@ -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;
}
+58
View File
@@ -0,0 +1,58 @@
<?php
declare(strict_types=1);
namespace Gii;
use Exception;
use Kiri\Abstracts\Config;
use Kiri\Abstracts\Input;
use Kiri\Exception\ComponentException;
use Kiri\Exception\ConfigException;
use Kiri\Exception\NotFindClassException;
use Kiri\Kiri;
use ReflectionException;
use Symfony\Component\Console\Command\Command;
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';
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return array
* @throws ComponentException
* @throws ConfigException
* @throws NotFindClassException
* @throws ReflectionException
*/
public function execute(InputInterface $input, OutputInterface $output): array
{
/** @var Gii $gii */
$gii = Kiri::app()->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;
}
}
+1 -1
View File
@@ -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('文件名称不能为空~');
}
+5 -4
View File
@@ -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));
}
}
+4 -4
View File
@@ -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 = '<?php
+2 -2
View File
@@ -21,12 +21,12 @@ class GiiRpcService extends GiiBase
public function generate(): array
{
$managerName = $this->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 = '<?php
+1 -1
View File
@@ -22,7 +22,7 @@ class GiiTask extends GiiBase
public function generate(): array
{
$managerName = $this->input->get('name', null);
$managerName = $this->input->getArgument('name', null);
if (empty($managerName)) {
throw new Exception('文件名称不能为空~');
}