...
|
...
|
@@ -20,7 +20,7 @@ class SwrpcGenCom extends Command |
|
|
*
|
|
|
* @var string
|
|
|
*/
|
|
|
protected $signature = 'swrpc:gen {-m|--module=}';
|
|
|
protected $signature = 'swrpc:gen {-m|--module=} {-s|--service=}';
|
|
|
|
|
|
/**
|
|
|
* The console command description.
|
...
|
...
|
@@ -55,20 +55,16 @@ class SwrpcGenCom extends Command |
|
|
|
|
|
$filters = [];
|
|
|
$specifyModules = $this->option('module') ? explode(',', $this->option('module')) : [];
|
|
|
$modules = Module::all();
|
|
|
print_r($modules);exit();
|
|
|
/** @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)) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
$moduleName = $module->getName();
|
|
|
$modulePath = str_replace('_', '/', $moduleName);
|
|
|
$moduleName = $key;
|
|
|
$modulePath = str_replace('\\', '/', $moduleName);
|
|
|
|
|
|
//create module dir
|
|
|
$basePath = base_path('app/Clients/' . $modulePath);
|
...
|
...
|
@@ -77,10 +73,9 @@ class SwrpcGenCom extends Command |
|
|
}
|
|
|
|
|
|
//target service namespace
|
|
|
$namespace = ltrim(str_replace([base_path(), '/'], ['', '\\'], $module->getPath()), '\\') . '\\Services';
|
|
|
|
|
|
$namespace = $key . 'Http\Service';
|
|
|
//fetch file
|
|
|
$servicePath = $module->getPath() . '/Services';
|
|
|
$servicePath = $prefix[0] . '/Http/Service';
|
|
|
if (!is_dir($servicePath)) {
|
|
|
continue;
|
|
|
}
|
...
|
...
|
@@ -111,7 +106,7 @@ class SwrpcGenCom extends Command |
|
|
$proxyPath = $basePath . '/' . $file;
|
|
|
ob_start();
|
|
|
ob_implicit_flush(false);
|
|
|
include(base_path('app/Clients/client.template.php'));
|
|
|
include(__DIR__.'/client.template.php');
|
|
|
$content = ob_get_clean();
|
|
|
if (!file_put_contents($proxyPath, $content)) {
|
|
|
$this->error($proxyPath . ' import failure.');
|
...
|
...
|
@@ -167,7 +162,7 @@ class SwrpcGenCom extends Command |
|
|
|
|
|
$serviceObj = $rc->newInstance();
|
|
|
if (!($serviceObj instanceof LogicService)) {
|
|
|
$this->warn('没有继承\Swrpc\LogicService类,跳过'.get_class($serviceObj));
|
|
|
$this->warn('没有继承\AukeySwrpc\LogicService类,跳过'.get_class($serviceObj));
|
|
|
return [];
|
|
|
}
|
|
|
|
...
|
...
|
|