作者 pengjch

dev: swrpc代码提交

... ... @@ -105,9 +105,16 @@ class BaseService
{
$moduleName = $this->extractModuleName();
/** @var \Nwidart\Modules\Laravel\Module $module */
$module = \Nwidart\Modules\Facades\Module::find($moduleName);
$moduleNs = ltrim(str_replace([base_path(), '/'], ['', '\\'], $module->getPath()), '\\');
return $moduleNs . '\\Services\\' . $this->extractServiceName();
// $loader = require base_path('vendor').'/autoload.php';
// // 获取注册的命名空间前缀并筛选出 Composer 包的命名空间
// $prefixes = $loader->getPrefixesPsr4();
// foreach ($prefixes as $key => $prefix) {
// if($moduleName.'\\' === $key){
//
// }
// }
// $moduleNs = ltrim(str_replace([base_path(), '/'], ['', '\\'], $module->getPath()), '\\');
return $moduleName . '\\Http\\Service\\' . $this->extractServiceName();
}
/**
... ...
... ... @@ -184,7 +184,6 @@ class Client
'package_body_offset' => $options['package_body_offset'] ?? 4,
]);
}
$request->setModule($this->module);
$conn->send($this->packer->pack($request));
... ...
... ... @@ -56,11 +56,11 @@ class SwrpcGenCom extends Command
$filters = [];
$specifyModules = $this->option('module') ? explode(',', $this->option('module')) : [];
$loader = require base_path('vendor').'/autoload.php';
// 获取注册的命名空间前缀并筛选出 Composer 包的命名空间
// 获取注册的命名空间前缀并筛选出 Composer 包的命名空间
$prefixes = $loader->getPrefixesPsr4();
foreach ($prefixes as $key => $prefix) {
//如果有指定moudle,则只有指定的moudle会生成,否则会生成全部
if (count($specifyModules) > 0 && !in_array($key, $specifyModules)) {
if (count($specifyModules) > 0 && !in_array($key, $specifyModules, true)) {
continue;
}
$moduleName = $key;
... ...
... ... @@ -126,7 +126,6 @@ class SwrpcServerCom extends Command
$this->error('SWRPC_SERVER_PORT未设置');
return -1;
}
$logger = new Logger('swrpc');
$logger->pushHandler(new StreamHandler(STDOUT, Logger::INFO));
$server = new Server($name, $host, $port, [
... ... @@ -140,21 +139,21 @@ class SwrpcServerCom extends Command
$filters = [];
$specifyModules = $this->option('module') ? explode(',', $this->option('module')) : [];
$modules = Module::all();
/** @var \Nwidart\Modules\Laravel\Module $module */
foreach ($modules as $module) {
if ($module->getName() == 'Common') {
continue;
}
$loader = require base_path('vendor').'/autoload.php';
// 获取注册的命名空间前缀并筛选出 Composer 包的命名空间
$prefixes = $loader->getPrefixesPsr4();
foreach ($prefixes as $key => $prefix) {
//如果有指定moudle,则只有指定的moudle会生成,否则会生成全部
if (count($specifyModules) > 0 && !in_array($module->getName(), $specifyModules)) {
if (count($specifyModules) > 0 && !in_array($key, $specifyModules, true)) {
continue;
}
$namespace = ltrim(str_replace([base_path(), '/'], ['', '\\'], $module->getPath()), '\\') . '\\Services\\';
$servicePath = $module->getPath() . '/Services';
$namespace = $key . 'Http\Service';
//fetch file
$servicePath = $prefix[0] . '/Http/Service';
if (!is_dir($servicePath)) {
continue;
}
$queues = scandir($servicePath);
while (count($queues) > 0) {
$file = array_shift($queues);
... ... @@ -199,7 +198,7 @@ class SwrpcServerCom extends Command
*/
protected function build($namespace, $class): ?object
{
$serviceClass = str_replace('/', '\\', $namespace . $class);
$serviceClass = str_replace('/', '\\', $namespace . '\\' . $class);
if (!class_exists($serviceClass)) {
$this->error($serviceClass . '类不存在');
return null;
... ...