改名
This commit is contained in:
@@ -95,6 +95,14 @@ class Gii
|
||||
$task = new GiiMiddleware();
|
||||
$task->setInput($this->input);
|
||||
return $task->generate();
|
||||
case 'rpc-client':
|
||||
$task = new GiiRpcClient();
|
||||
$task->setInput($this->input);
|
||||
return $task->generate();
|
||||
case 'rpc-service':
|
||||
$task = new GiiRpcService();
|
||||
$task->setInput($this->input);
|
||||
return $task->generate();
|
||||
default:
|
||||
return $this->getModel($make, $input);
|
||||
}
|
||||
|
||||
@@ -1,87 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Gii;
|
||||
|
||||
use Annotation\Inject;
|
||||
use Snowflake\Abstracts\Config;
|
||||
use Snowflake\Core\Json;
|
||||
use Snowflake\Exception\ComponentException;
|
||||
use Snowflake\Exception\ConfigException;
|
||||
use Snowflake\Exception\NotFindClassException;
|
||||
use Snowflake\Snowflake;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Class MakeGiiProviders
|
||||
* @package Gii
|
||||
*/
|
||||
class GiiConsole extends Command
|
||||
{
|
||||
|
||||
#[Inject(Gii::class)]
|
||||
public ?Gii $gii = null;
|
||||
|
||||
|
||||
public function configure()
|
||||
{
|
||||
$this->setName('sw:gii')
|
||||
->setDescription('create default file.')
|
||||
->setHelp('make=model|controller|task|interceptor|limits|middleware name=xxxx');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param InputInterface $input
|
||||
* @param OutputInterface $output
|
||||
* @throws \ReflectionException
|
||||
* @throws NotFindClassException
|
||||
*/
|
||||
protected function initialize(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->gii = Snowflake::createObject(Gii::class);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param InputInterface $input
|
||||
* @param OutputInterface $output
|
||||
* @return int
|
||||
* @throws ComponentException
|
||||
* @throws ConfigException
|
||||
*/
|
||||
public function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$output->writeln('start generate. Please waite...');
|
||||
$connections = Snowflake::app()->get('db');
|
||||
if ($input->getArgument('databases')) {
|
||||
$array = $this->gii->run($connections->get($input->getArgument('databases')), $input);
|
||||
} else {
|
||||
$array = $this->batchCreate($input, $this->gii, $connections);
|
||||
}
|
||||
$output->writeln('create file [' . Json::encode($array) . ']');
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param InputInterface $input
|
||||
* @param $gii
|
||||
* @param $connections
|
||||
* @return array
|
||||
* @throws ConfigException
|
||||
*/
|
||||
private function batchCreate(InputInterface $input, $gii, $connections): array
|
||||
{
|
||||
$array = [];
|
||||
foreach (Config::get('databases') as $key => $connection) {
|
||||
$array[$key] = $gii->run($connections->get($key), $input);
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -88,7 +88,7 @@ class ' . $managerName . 'Interceptor implements Interceptor
|
||||
|
||||
|
||||
if (file_exists($file)) {
|
||||
unlink($file);
|
||||
throw new Exception('File exists.');
|
||||
}
|
||||
|
||||
Snowflake::writeFile($file, $html);
|
||||
|
||||
+1
-1
@@ -65,7 +65,7 @@ class ' . $managerName . 'Limits implements Limits
|
||||
|
||||
$file = APP_PATH . 'app/Http/Limits/' . $managerName . 'Limits.php';
|
||||
if (file_exists($file)) {
|
||||
unlink($file);
|
||||
throw new Exception('File exists.');
|
||||
}
|
||||
|
||||
Snowflake::writeFile($file, $html);
|
||||
|
||||
@@ -62,7 +62,7 @@ class ' . $managerName . 'Middleware implements Middleware
|
||||
|
||||
$file = APP_PATH . 'app/Http/Middleware/' . $managerName . 'Middleware.php';
|
||||
if (file_exists($file)) {
|
||||
unlink($file);
|
||||
throw new Exception('File exists.');
|
||||
}
|
||||
|
||||
Snowflake::writeFile($file, $html);
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Gii;
|
||||
|
||||
|
||||
use Exception;
|
||||
use Snowflake\Snowflake;
|
||||
|
||||
/**
|
||||
* Class GiiRpcClient
|
||||
* @package Gii
|
||||
*/
|
||||
class GiiRpcClient extends GiiBase
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function generate(): array
|
||||
{
|
||||
|
||||
$managerName = $this->input->get('name', null);
|
||||
if (empty($managerName)) {
|
||||
throw new Exception('文件名称不能为空~');
|
||||
}
|
||||
|
||||
$service = $this->input->get('service', strtolower($managerName));
|
||||
|
||||
$port = $this->input->get('port', 443);
|
||||
$mode = $this->input->get('mode', 'SWOOLE_SOCK_TCP');
|
||||
|
||||
$html = '<?php
|
||||
|
||||
|
||||
namespace App\Client\Rpc;
|
||||
|
||||
use Annotation\Rpc\Consumer;
|
||||
use Annotation\Rpc\RpcClient;
|
||||
use Annotation\Target;
|
||||
use Exception;
|
||||
use Rpc\Client;
|
||||
use Snowflake\Core\Json;
|
||||
use Snowflake\Snowflake;
|
||||
|
||||
';
|
||||
|
||||
$managerName = ucfirst($managerName);
|
||||
$html .= '
|
||||
/**
|
||||
* Class ' . $managerName . 'Consumer
|
||||
* @package App\Client\Rpc
|
||||
*/
|
||||
#[Target]
|
||||
#[RpcClient(cmd: \'' . $service . '\', port: ' . $port . ', timeout: 1, mode: ' . $mode . ')]
|
||||
class ' . $managerName . 'Consumer extends \Rpc\Consumer
|
||||
{
|
||||
|
||||
public array $node = [\'host\' => \'127.0.0.1\', \'port\' => 5377];
|
||||
|
||||
|
||||
/**
|
||||
* @return Client
|
||||
* @throws Exception
|
||||
*/
|
||||
public function initClient(): Client
|
||||
{
|
||||
// TODO: Implement initClient() method.
|
||||
return $this->client = $this->rpc->getClient(\'' . $service . '\');
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param Users $users
|
||||
* @param string $event
|
||||
* @param array $params
|
||||
* @throws Exception
|
||||
*/
|
||||
#[Consumer(\'default\')]
|
||||
public function push(Users $users, string $event, array $params)
|
||||
{
|
||||
|
||||
}
|
||||
}';
|
||||
|
||||
if (!is_dir(APP_PATH . 'app/Client/Rpc/')) {
|
||||
mkdir(APP_PATH . 'app/Client/Rpc/', 0777, true);
|
||||
}
|
||||
|
||||
$file = APP_PATH . 'app/Client/Rpc/' . $managerName . 'Middleware.php';
|
||||
if (file_exists($file)) {
|
||||
throw new Exception('File exists.');
|
||||
}
|
||||
|
||||
Snowflake::writeFile($file, $html);
|
||||
return [$managerName . 'Middleware.php'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Gii;
|
||||
|
||||
|
||||
use Exception;
|
||||
use Snowflake\Snowflake;
|
||||
|
||||
/**
|
||||
* Class GiiRpcClient
|
||||
* @package Gii
|
||||
*/
|
||||
class GiiRpcService extends GiiBase
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function generate(): array
|
||||
{
|
||||
|
||||
$managerName = $this->input->get('name', null);
|
||||
if (empty($managerName)) {
|
||||
throw new Exception('文件名称不能为空~');
|
||||
}
|
||||
|
||||
$service = $this->input->get('service', strtolower($managerName));
|
||||
|
||||
$port = $this->input->get('port', 443);
|
||||
|
||||
$html = '<?php
|
||||
|
||||
|
||||
namespace App\Http\Rpc;
|
||||
|
||||
use Annotation\Route\RpcProducer;
|
||||
use Annotation\Target;
|
||||
use Exception;
|
||||
use HttpServer\Controller;
|
||||
use HttpServer\Exception\RequestException;
|
||||
use Snowflake\Core\Json;
|
||||
|
||||
';
|
||||
|
||||
$managerName = ucfirst($managerName);
|
||||
$html .= '
|
||||
/**
|
||||
* Class ' . $managerName . 'Consumer
|
||||
* @package App\Client\Rpc
|
||||
*/
|
||||
#[Target]
|
||||
class ' . $managerName . 'Producer extends Controller
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @param Users $users
|
||||
* @param string $event
|
||||
* @param array $params
|
||||
* @throws Exception
|
||||
*/
|
||||
#[RpcProducer(cmd: \'default\', port: ' . $port . ')]
|
||||
public function actionIndex()
|
||||
{
|
||||
|
||||
}
|
||||
}';
|
||||
|
||||
if (!is_dir(APP_PATH . 'app/Http/Rpc/')) {
|
||||
mkdir(APP_PATH . 'app/Http/Rpc/', 0777, true);
|
||||
}
|
||||
|
||||
$file = APP_PATH . 'app/Http/Rpc/' . $managerName . 'Producer.php';
|
||||
if (file_exists($file)) {
|
||||
throw new Exception('File exists.');
|
||||
}
|
||||
|
||||
Snowflake::writeFile($file, $html);
|
||||
return [$managerName . 'Producer.php'];
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -80,7 +80,7 @@ class ' . $managerName . ' implements Task
|
||||
|
||||
$file = APP_PATH . 'app/Async/' . $managerName . '.php';
|
||||
if (file_exists($file)) {
|
||||
unlink($file);
|
||||
throw new Exception('File exists.');
|
||||
}
|
||||
|
||||
Snowflake::writeFile($file, $html);
|
||||
|
||||
Reference in New Issue
Block a user