diff --git a/Gii/Gii.php b/Gii/Gii.php index 95482bfb..645bc9fb 100644 --- a/Gii/Gii.php +++ b/Gii/Gii.php @@ -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); } diff --git a/Gii/GiiConsole.php b/Gii/GiiConsole.php deleted file mode 100644 index 0536e8c4..00000000 --- a/Gii/GiiConsole.php +++ /dev/null @@ -1,87 +0,0 @@ -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; - } - - -} diff --git a/Gii/GiiInterceptor.php b/Gii/GiiInterceptor.php index 5d6005a3..707f5ef7 100644 --- a/Gii/GiiInterceptor.php +++ b/Gii/GiiInterceptor.php @@ -88,7 +88,7 @@ class ' . $managerName . 'Interceptor implements Interceptor if (file_exists($file)) { - unlink($file); + throw new Exception('File exists.'); } Snowflake::writeFile($file, $html); diff --git a/Gii/GiiLimits.php b/Gii/GiiLimits.php index dfa5395e..d2233701 100644 --- a/Gii/GiiLimits.php +++ b/Gii/GiiLimits.php @@ -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); diff --git a/Gii/GiiMiddleware.php b/Gii/GiiMiddleware.php index f8ec7a17..43bd4318 100644 --- a/Gii/GiiMiddleware.php +++ b/Gii/GiiMiddleware.php @@ -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); diff --git a/Gii/GiiRpcClient.php b/Gii/GiiRpcClient.php new file mode 100644 index 00000000..146955d2 --- /dev/null +++ b/Gii/GiiRpcClient.php @@ -0,0 +1,100 @@ +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 = ' \'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']; + } +} diff --git a/Gii/GiiRpcService.php b/Gii/GiiRpcService.php new file mode 100644 index 00000000..edef6d20 --- /dev/null +++ b/Gii/GiiRpcService.php @@ -0,0 +1,83 @@ +input->get('name', null); + if (empty($managerName)) { + throw new Exception('文件名称不能为空~'); + } + + $service = $this->input->get('service', strtolower($managerName)); + + $port = $this->input->get('port', 443); + + $html = '