改名
This commit is contained in:
@@ -89,6 +89,10 @@ class Gii
|
|||||||
$task = new GiiRpcService();
|
$task = new GiiRpcService();
|
||||||
$task->setInput($this->input);
|
$task->setInput($this->input);
|
||||||
return $task->generate();
|
return $task->generate();
|
||||||
|
case 'json-rpc':
|
||||||
|
$task = new GiiJsonRpc();
|
||||||
|
$task->setInput($this->input);
|
||||||
|
return $task->create();
|
||||||
default:
|
default:
|
||||||
return $this->getModel($make, $input);
|
return $this->getModel($make, $input);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,9 +40,8 @@ class GiiCommand extends Command
|
|||||||
/**
|
/**
|
||||||
* @param InputInterface $input
|
* @param InputInterface $input
|
||||||
* @param OutputInterface $output
|
* @param OutputInterface $output
|
||||||
* @return array
|
* @return int
|
||||||
* @throws ConfigException
|
* @throws ConfigException
|
||||||
* @throws Exception
|
|
||||||
*/
|
*/
|
||||||
public function execute(InputInterface $input, OutputInterface $output): int
|
public function execute(InputInterface $input, OutputInterface $output): int
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,108 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Gii;
|
||||||
|
|
||||||
|
class GiiJsonRpc extends GiiBase
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function create(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
$this->createInterface($this->input->getArgument('name')),
|
||||||
|
$this->createProducers($this->input->getArgument('name')),
|
||||||
|
$this->createConsumer($this->input->getArgument('name')),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private function createInterface($name)
|
||||||
|
{
|
||||||
|
$html = '<?php
|
||||||
|
|
||||||
|
namespace Rpc;
|
||||||
|
|
||||||
|
interface ' . ucfirst($name) . 'RpcInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
';
|
||||||
|
|
||||||
|
|
||||||
|
$name = ucfirst($name) . 'RpcInterface.php';
|
||||||
|
if (!is_dir(APP_PATH . '/rpc/')) {
|
||||||
|
mkdir(APP_PATH . '/rpc/');
|
||||||
|
}
|
||||||
|
file_put_contents(APP_PATH . '/rpc/' . $name, $html);
|
||||||
|
|
||||||
|
return $name;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private function createProducers($name)
|
||||||
|
{
|
||||||
|
$html = '<?php
|
||||||
|
|
||||||
|
use Annotation\Target;
|
||||||
|
use Http\Handler\Controller;
|
||||||
|
use Kiri\Rpc\Annotation\JsonRpc;
|
||||||
|
use Rpc\\' . ucfirst($name) . 'RpcInterface;
|
||||||
|
|
||||||
|
|
||||||
|
#[Target]
|
||||||
|
#[JsonRpc(method: \'test\', version: \'2.0\')]
|
||||||
|
class ' . ucfirst($name) . 'RpcController extends Controller implements ' . ucfirst($name) . 'RpcInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
';
|
||||||
|
|
||||||
|
$name = ucfirst($name) . 'RpcController.php';
|
||||||
|
if (!is_dir(APP_PATH . '/rpc/Producers/')) {
|
||||||
|
mkdir(APP_PATH . '/rpc/Producers/');
|
||||||
|
}
|
||||||
|
file_put_contents(APP_PATH . '/rpc/Producers/' . $name, $html);
|
||||||
|
|
||||||
|
return $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private function createConsumer($name)
|
||||||
|
{
|
||||||
|
$html = '<?php
|
||||||
|
|
||||||
|
use Annotation\Target;
|
||||||
|
use Http\Handler\Controller;
|
||||||
|
use Kiri\Rpc\Annotation\JsonRpc;
|
||||||
|
use Rpc\\' . ucfirst($name) . 'RpcInterface;
|
||||||
|
|
||||||
|
|
||||||
|
#[Target]
|
||||||
|
#[JsonRpc(method: \'test\', version: \'2.0\')]
|
||||||
|
class ' . ucfirst($name) . 'RpcConsumer extends JsonRpcConsumers implements ' . ucfirst($name) . 'RpcInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
';
|
||||||
|
|
||||||
|
$name = ucfirst($name) . 'RpcConsumer.php';
|
||||||
|
if (!is_dir(APP_PATH . '/rpc/Consumers/')) {
|
||||||
|
mkdir(APP_PATH . '/rpc/Consumers/');
|
||||||
|
}
|
||||||
|
file_put_contents(APP_PATH . '/rpc/Consumers/' . $name, $html);
|
||||||
|
|
||||||
|
return $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user