改名
This commit is contained in:
+16
-16
@@ -16,6 +16,8 @@ use Server\Events\OnBeforeWorkerStart;
|
|||||||
use Server\Events\OnWorkerStart;
|
use Server\Events\OnWorkerStart;
|
||||||
use Server\Worker\OnServerWorker;
|
use Server\Worker\OnServerWorker;
|
||||||
use Server\Worker\OnWorkerStart as WorkerDispatch;
|
use Server\Worker\OnWorkerStart as WorkerDispatch;
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Command
|
* Class Command
|
||||||
@@ -24,11 +26,6 @@ use Server\Worker\OnWorkerStart as WorkerDispatch;
|
|||||||
class Command extends \Symfony\Component\Console\Command\Command
|
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'];
|
const ACTIONS = ['start', 'stop', 'restart'];
|
||||||
|
|
||||||
@@ -45,30 +42,33 @@ class Command extends \Symfony\Component\Console\Command\Command
|
|||||||
*/
|
*/
|
||||||
protected function configure()
|
protected function configure()
|
||||||
{
|
{
|
||||||
$this->setName('swoole')
|
$this->setName('sw:server')
|
||||||
->setDescription('server start|stop|reload|restart');
|
->setDescription('server start|stop|reload|restart');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Input $dtl
|
* @param InputInterface $input
|
||||||
|
* @param OutputInterface $output
|
||||||
* @return string
|
* @return string
|
||||||
* @throws Exception
|
|
||||||
* @throws ConfigException
|
* @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 = Kiri::app()->getServer();
|
||||||
$manager->setDaemon($dtl->get('daemon', 0));
|
$manager->setDaemon($input->getArgument('daemon'));
|
||||||
if (!in_array($dtl->get('action'), self::ACTIONS)) {
|
if (!in_array($input->getArgument('action'), self::ACTIONS)) {
|
||||||
return 'I don\'t know what I want to do.';
|
return $output->write('I don\'t know what I want to do.');
|
||||||
}
|
}
|
||||||
if ($manager->isRunner() && $dtl->get('action') == 'start') {
|
if ($manager->isRunner() && $input->getArgument('action') == 'start') {
|
||||||
return 'Service is running. Please use restart.';
|
return $output->write('Service is running. Please use restart.');
|
||||||
}
|
}
|
||||||
$manager->shutdown();
|
$manager->shutdown();
|
||||||
if ($dtl->get('action') == 'stop') {
|
if ($input->getArgument('action') == 'stop') {
|
||||||
return 'shutdown success.';
|
return $output->write('shutdown success');
|
||||||
}
|
}
|
||||||
return $this->generate_runtime_builder($manager);
|
return $this->generate_runtime_builder($manager);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ declare(strict_types=1);
|
|||||||
namespace Http;
|
namespace Http;
|
||||||
|
|
||||||
|
|
||||||
use Console\Console;
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Kiri\Abstracts\Providers;
|
use Kiri\Abstracts\Providers;
|
||||||
use Kiri\Application;
|
use Kiri\Application;
|
||||||
|
use Kiri\Kiri;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class DatabasesProviders
|
* Class DatabasesProviders
|
||||||
@@ -25,8 +25,10 @@ class ServerProviders extends Providers
|
|||||||
{
|
{
|
||||||
$application->set('server', ['class' => Server::class]);
|
$application->set('server', ['class' => Server::class]);
|
||||||
|
|
||||||
/** @var Console $console */
|
$container = Kiri::getDi();
|
||||||
$console = $application->get('console');
|
|
||||||
$console->register(Command::class);
|
$console = $container->get(\Symfony\Component\Console\Application::class);
|
||||||
|
$console->add($container->get(Command::class));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
@@ -12,10 +12,10 @@ namespace Gii;
|
|||||||
use Database\Connection;
|
use Database\Connection;
|
||||||
use Database\Db;
|
use Database\Db;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Kiri\Abstracts\Input;
|
|
||||||
use Kiri\Exception\ComponentException;
|
use Kiri\Exception\ComponentException;
|
||||||
use Kiri\Exception\ConfigException;
|
use Kiri\Exception\ConfigException;
|
||||||
use Kiri\Kiri;
|
use Kiri\Kiri;
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class gii
|
* Class gii
|
||||||
@@ -29,8 +29,7 @@ class Gii
|
|||||||
/** @var Connection */
|
/** @var Connection */
|
||||||
private Connection $db;
|
private Connection $db;
|
||||||
|
|
||||||
/** @var Input */
|
private InputInterface $input;
|
||||||
private Input $input;
|
|
||||||
|
|
||||||
public string $modelPath = APP_PATH . 'app/Models/';
|
public string $modelPath = APP_PATH . 'app/Models/';
|
||||||
public string $modelNamespace = 'App\\Models\\';
|
public string $modelNamespace = 'App\\Models\\';
|
||||||
@@ -49,32 +48,31 @@ class Gii
|
|||||||
/**
|
/**
|
||||||
* @param Connection|null $db
|
* @param Connection|null $db
|
||||||
*
|
*
|
||||||
* @param $input
|
* @param InputInterface $input
|
||||||
* @return array
|
* @return array
|
||||||
* @throws ComponentException
|
* @throws ComponentException
|
||||||
* @throws ConfigException
|
* @throws ConfigException
|
||||||
* @throws Exception
|
|
||||||
*/
|
*/
|
||||||
public function run(?Connection $db, $input): array
|
public function run(?Connection $db, InputInterface $input): array
|
||||||
{
|
{
|
||||||
return $this->gen($input, $db);
|
return $this->gen($input, $db);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $input
|
* @param InputInterface $input
|
||||||
* @param $db
|
* @param $db
|
||||||
* @return array
|
* @return array
|
||||||
* @throws ComponentException
|
* @throws ComponentException
|
||||||
* @throws ConfigException
|
* @throws ConfigException
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function gen($input, $db): array
|
public function gen(InputInterface $input, $db): array
|
||||||
{
|
{
|
||||||
$this->input = $input;
|
$this->input = $input;
|
||||||
if (!empty($db)) $this->db = $db;
|
if (!empty($db)) $this->db = $db;
|
||||||
|
|
||||||
$make = $this->input->get('make', null);
|
$make = $this->input->getArgument('make');
|
||||||
if (empty($make)) {
|
if (empty($make)) {
|
||||||
throw new Exception('构建类型不能为空~');
|
throw new Exception('构建类型不能为空~');
|
||||||
}
|
}
|
||||||
@@ -83,14 +81,6 @@ class Gii
|
|||||||
$task = new GiiTask();
|
$task = new GiiTask();
|
||||||
$task->setInput($this->input);
|
$task->setInput($this->input);
|
||||||
return $task->generate();
|
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':
|
case 'middleware':
|
||||||
$task = new GiiMiddleware();
|
$task = new GiiMiddleware();
|
||||||
$task->setInput($this->input);
|
$task->setInput($this->input);
|
||||||
@@ -114,7 +104,6 @@ class Gii
|
|||||||
* @param $input
|
* @param $input
|
||||||
* @return array
|
* @return array
|
||||||
* @throws ComponentException
|
* @throws ComponentException
|
||||||
* @throws ConfigException
|
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private function getModel($make, $input): array
|
private function getModel($make, $input): array
|
||||||
@@ -122,7 +111,7 @@ class Gii
|
|||||||
if ($this->db instanceof Connection) {
|
if ($this->db instanceof Connection) {
|
||||||
return $this->makeByDatabases($make, $input);
|
return $this->makeByDatabases($make, $input);
|
||||||
}
|
}
|
||||||
$db = $this->input->get('databases', 'db');
|
$db = $this->input->getArgument('databases');
|
||||||
$this->db = Kiri::app()->get('db')->get($db);
|
$this->db = Kiri::app()->get('db')->get($db);
|
||||||
|
|
||||||
return $this->makeByDatabases($make, $input);
|
return $this->makeByDatabases($make, $input);
|
||||||
@@ -131,16 +120,15 @@ class Gii
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $make
|
* @param $make
|
||||||
* @param $input
|
* @param InputInterface $input
|
||||||
* @return array
|
* @return array
|
||||||
* @throws ComponentException
|
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private function makeByDatabases($make, $input): array
|
private function makeByDatabases($make, InputInterface $input): array
|
||||||
{
|
{
|
||||||
$redis = Kiri::app()->getRedis();
|
$redis = Kiri::app()->getRedis();
|
||||||
if (!empty($input->get('name'))) {
|
if (!empty($input->getArgument('name'))) {
|
||||||
$this->tableName = $input->get('name');
|
$this->tableName = $input->getArgument('name');
|
||||||
$redis->del('column:' . $this->tableName);
|
$redis->del('column:' . $this->tableName);
|
||||||
}
|
}
|
||||||
return match ($make) {
|
return match ($make) {
|
||||||
@@ -190,7 +178,7 @@ class Gii
|
|||||||
$controller->setModelPath($this->modelPath);
|
$controller->setModelPath($this->modelPath);
|
||||||
$controller->setModelNamespace($this->modelNamespace);
|
$controller->setModelNamespace($this->modelNamespace);
|
||||||
$controller->setInput($this->input);
|
$controller->setInput($this->input);
|
||||||
$controller->setModule($this->input->get('module', null));
|
$controller->setModule($this->input->getArgument('module'));
|
||||||
$controller->setControllerPath($this->controllerPath);
|
$controller->setControllerPath($this->controllerPath);
|
||||||
$controller->setControllerNamespace($this->controllerNamespace);
|
$controller->setControllerNamespace($this->controllerNamespace);
|
||||||
return $controller->generate();
|
return $controller->generate();
|
||||||
@@ -209,7 +197,7 @@ class Gii
|
|||||||
$controller->setInput($this->input);
|
$controller->setInput($this->input);
|
||||||
$controller->setModelNamespace($this->modelNamespace);
|
$controller->setModelNamespace($this->modelNamespace);
|
||||||
$controller->setControllerPath($this->controllerPath);
|
$controller->setControllerPath($this->controllerPath);
|
||||||
$controller->setModule($this->input->get('module', null));
|
$controller->setModule($this->input->getArgument('module'));
|
||||||
$controller->setControllerNamespace($this->controllerNamespace);
|
$controller->setControllerNamespace($this->controllerNamespace);
|
||||||
return $controller->generate();
|
return $controller->generate();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ use ReflectionClass;
|
|||||||
use ReflectionException;
|
use ReflectionException;
|
||||||
use Kiri\Abstracts\Input;
|
use Kiri\Abstracts\Input;
|
||||||
use Kiri\Core\Json;
|
use Kiri\Core\Json;
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class GiiBase
|
* Class GiiBase
|
||||||
@@ -24,8 +25,7 @@ abstract class GiiBase
|
|||||||
public array $fileList = [];
|
public array $fileList = [];
|
||||||
|
|
||||||
|
|
||||||
/** @var Input */
|
protected InputInterface $input;
|
||||||
protected Input $input;
|
|
||||||
|
|
||||||
public string $modelPath = APP_PATH . 'app/Models/';
|
public string $modelPath = APP_PATH . 'app/Models/';
|
||||||
public string $modelNamespace = '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;
|
$this->input = $input;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -23,7 +23,7 @@ class GiiMiddleware extends GiiBase
|
|||||||
public function generate(): array
|
public function generate(): array
|
||||||
{
|
{
|
||||||
|
|
||||||
$managerName = $this->input->get('name', null);
|
$managerName = $this->input->getArgument('name');
|
||||||
if (empty($managerName)) {
|
if (empty($managerName)) {
|
||||||
throw new Exception('文件名称不能为空~');
|
throw new Exception('文件名称不能为空~');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,10 +5,10 @@ declare(strict_types=1);
|
|||||||
namespace Gii;
|
namespace Gii;
|
||||||
|
|
||||||
|
|
||||||
use Console\Console;
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Kiri\Abstracts\Providers;
|
use Kiri\Abstracts\Providers;
|
||||||
use Kiri\Application;
|
use Kiri\Application;
|
||||||
|
use Kiri\Kiri;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class DatabasesProviders
|
* Class DatabasesProviders
|
||||||
@@ -26,8 +26,9 @@ class GiiProviders extends Providers
|
|||||||
{
|
{
|
||||||
$application->set('gii', ['class' => Gii::class]);
|
$application->set('gii', ['class' => Gii::class]);
|
||||||
|
|
||||||
/** @var Console $console */
|
$container = Kiri::getDi();
|
||||||
$console = $application->get('console');
|
|
||||||
$console->register(Command::class);
|
$console = $container->get(\Symfony\Component\Console\Application::class);
|
||||||
|
$console->add($container->get(GiiCommand::class));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,15 +21,15 @@ class GiiRpcClient extends GiiBase
|
|||||||
public function generate(): array
|
public function generate(): array
|
||||||
{
|
{
|
||||||
|
|
||||||
$managerName = $this->input->get('name', null);
|
$managerName = $this->input->getArgument('name', null);
|
||||||
if (empty($managerName)) {
|
if (empty($managerName)) {
|
||||||
throw new Exception('文件名称不能为空~');
|
throw new Exception('文件名称不能为空~');
|
||||||
}
|
}
|
||||||
|
|
||||||
$service = $this->input->get('service', strtolower($managerName));
|
$service = $this->input->getArgument('service', strtolower($managerName));
|
||||||
|
|
||||||
$port = $this->input->get('port', 443);
|
$port = $this->input->getArgument('port', 443);
|
||||||
$mode = $this->input->get('mode', 'SWOOLE_SOCK_TCP');
|
$mode = $this->input->getArgument('mode', 'SWOOLE_SOCK_TCP');
|
||||||
|
|
||||||
$html = '<?php
|
$html = '<?php
|
||||||
|
|
||||||
|
|||||||
@@ -21,12 +21,12 @@ class GiiRpcService extends GiiBase
|
|||||||
public function generate(): array
|
public function generate(): array
|
||||||
{
|
{
|
||||||
|
|
||||||
$managerName = $this->input->get('name', null);
|
$managerName = $this->input->getArgument('name', null);
|
||||||
if (empty($managerName)) {
|
if (empty($managerName)) {
|
||||||
throw new Exception('文件名称不能为空~');
|
throw new Exception('文件名称不能为空~');
|
||||||
}
|
}
|
||||||
|
|
||||||
$port = $this->input->get('port', 443);
|
$port = $this->input->getArgument('port', 443);
|
||||||
|
|
||||||
$html = '<?php
|
$html = '<?php
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class GiiTask extends GiiBase
|
|||||||
public function generate(): array
|
public function generate(): array
|
||||||
{
|
{
|
||||||
|
|
||||||
$managerName = $this->input->get('name', null);
|
$managerName = $this->input->getArgument('name', null);
|
||||||
if (empty($managerName)) {
|
if (empty($managerName)) {
|
||||||
throw new Exception('文件名称不能为空~');
|
throw new Exception('文件名称不能为空~');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user