modify plugin name

This commit is contained in:
2022-03-17 10:35:14 +08:00
parent 334f7de552
commit a689474053
12 changed files with 2303 additions and 0 deletions
+79
View File
@@ -0,0 +1,79 @@
<?php
namespace Gii;
use Exception;
use Kiri;
use const APP_PATH;
/**
* Class GiiRpcClient
* @package Gii
*/
class GiiRpcService extends GiiBase
{
/**
* @return array
* @throws Exception
*/
public function generate(): array
{
$managerName = $this->input->getArgument('name', null);
if (empty($managerName)) {
throw new Exception('文件名称不能为空~');
}
$port = $this->input->getArgument('port', 443);
$html = '<?php
namespace App\Rpc;
use Kiri\Annotation\Route\RpcProducer;
use Kiri\Annotation\Target;
use Exception;
use Kiri\Message\Controller;
use Kiri\Core\Json;
';
$managerName = ucfirst($managerName);
$html .= '
/**
* Class ' . $managerName . 'Consumer
* @package App\Client\Rpc
*/
#[Target]
class ' . $managerName . 'Producer extends Controller
{
/**
* @param array $params
* @throws Exception
*/
#[RpcProducer(cmd: \'default\', port: ' . $port . ')]
public function actionIndex(array $params)
{
}
}';
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.');
}
Kiri::writeFile($file, $html);
return [$managerName . 'Producer.php'];
}
}