add packer namespace adjust (build 441)

This commit is contained in:
crazywhalecc
2022-03-20 16:18:33 +08:00
parent 69155002dc
commit 78f78c607d
2 changed files with 21 additions and 4 deletions

View File

@@ -28,7 +28,7 @@ use ZM\Exception\InitException;
class ConsoleApplication extends Application class ConsoleApplication extends Application
{ {
public const VERSION_ID = 440; public const VERSION_ID = 441;
public const VERSION = '2.7.0-beta4'; public const VERSION = '2.7.0-beta4';
@@ -87,11 +87,11 @@ class ConsoleApplication extends Application
new DaemonStatusCommand(), new DaemonStatusCommand(),
new DaemonReloadCommand(), new DaemonReloadCommand(),
new DaemonStopCommand(), new DaemonStopCommand(),
new RunServerCommand(), //运行主服务的指令控制器 new RunServerCommand(), // 运行主服务的指令控制器
new ServerStatusCommand(), new ServerStatusCommand(),
new ServerStopCommand(), new ServerStopCommand(),
new ServerReloadCommand(), new ServerReloadCommand(),
new PureHttpCommand(), //纯HTTP服务器指令 new PureHttpCommand(), // 纯HTTP服务器指令
new SystemdGenerateCommand(), new SystemdGenerateCommand(),
]); ]);
if (LOAD_MODE === 1) { if (LOAD_MODE === 1) {

View File

@@ -20,12 +20,18 @@ use ZM\Utils\DataProvider;
*/ */
class ModuleManager class ModuleManager
{ {
public static function getComposer()
{
return json_decode(file_get_contents(DataProvider::getSourceRootDir() . '/composer.json'), true);
}
/** /**
* 扫描src目录下的所有已经被标注的模块 * 扫描src目录下的所有已经被标注的模块
* @throws ZMException * @throws ZMException
*/ */
public static function getConfiguredModules(): array public static function getConfiguredModules(): array
{ {
$composer = self::getComposer();
$dir = DataProvider::getSourceRootDir() . '/src/'; $dir = DataProvider::getSourceRootDir() . '/src/';
$ls = DataProvider::scanDirFiles($dir, true, true); $ls = DataProvider::scanDirFiles($dir, true, true);
$modules = []; $modules = [];
@@ -43,7 +49,18 @@ class ModuleManager
throw new ZMKnownException('E00052', '在/src/目录下不可以直接标记为模块(zm.json),因为命名空间不能为根空间!'); throw new ZMKnownException('E00052', '在/src/目录下不可以直接标记为模块(zm.json),因为命名空间不能为根空间!');
} }
$json['module-path'] = realpath($dir . '/' . $pathinfo['dirname']); $json['module-path'] = realpath($dir . '/' . $pathinfo['dirname']);
$json['namespace'] = str_replace('/', '\\', $pathinfo['dirname']);
$relative_path = str_replace(DataProvider::getSourceRootDir() . '/', '', $json['module-path']);
foreach (array_merge($composer['autoload']['psr-4'] ?? [], $composer['autoload-dev']['psr-4'] ?? []) as $ks => $vs) {
if (strpos($relative_path, $vs) === 0) {
$remain = trim(substr($relative_path, strlen($vs)), '/');
$remain = str_replace('/', '\\', $remain);
$json['namespace'] = $ks . $remain;
break;
}
}
// $json['namespace'] = str_replace('/', '\\', $pathinfo['dirname']);
if (isset($modules[$json['name']])) { if (isset($modules[$json['name']])) {
throw new ZMKnownException('E00053', '重名模块:' . $json['name']); throw new ZMKnownException('E00053', '重名模块:' . $json['name']);
} }