fix unpack autoload not working, change exclude_annotate to another name (build 444)

This commit is contained in:
crazywhalecc
2022-03-20 16:51:48 +08:00
parent 7ce3ef41df
commit 74e91a2950
5 changed files with 18 additions and 11 deletions

View File

@@ -4,9 +4,11 @@
"minimum-stability": "stable", "minimum-stability": "stable",
"license": "Apache-2.0", "license": "Apache-2.0",
"extra": { "extra": {
"exclude_annotate": [ "zm": {
"src/ZM" "exclude-annotation-path": [
], "src/ZM"
]
},
"hooks": { "hooks": {
"post-merge": "composer install", "post-merge": "composer install",
"pre-commit": [ "pre-commit": [

View File

@@ -28,7 +28,7 @@ use ZM\Exception\InitException;
class ConsoleApplication extends Application class ConsoleApplication extends Application
{ {
public const VERSION_ID = 443; public const VERSION_ID = 444;
public const VERSION = '2.7.0-beta4'; public const VERSION = '2.7.0-beta4';

View File

@@ -156,9 +156,10 @@ class OnWorkerStart implements SwooleEvent
$parser = new AnnotationParser(); $parser = new AnnotationParser();
$composer = json_decode(file_get_contents(DataProvider::getSourceRootDir() . '/composer.json'), true); $composer = json_decode(file_get_contents(DataProvider::getSourceRootDir() . '/composer.json'), true);
$merge = array_merge($composer['autoload']['psr-4'] ?? [], $composer['autoload-dev']['psr-4'] ?? []); $merge = array_merge($composer['autoload']['psr-4'] ?? [], $composer['autoload-dev']['psr-4'] ?? []);
$exclude_annotations = array_merge($composer['extra']['exclude_annotate'] ?? [], $composer['extra']['zm']['exclude-annotation-path'] ?? []);
foreach ($merge as $k => $v) { foreach ($merge as $k => $v) {
if (is_dir(DataProvider::getSourceRootDir() . '/' . $v)) { if (is_dir(DataProvider::getSourceRootDir() . '/' . $v)) {
if (in_array(trim($k, '\\') . '\\', $composer['extra']['exclude_annotate'] ?? [])) { if (in_array(trim($k, '\\') . '\\', $exclude_annotations)) {
continue; continue;
} }
if (trim($k, '\\') == 'ZM') { if (trim($k, '\\') == 'ZM') {

View File

@@ -30,7 +30,8 @@ class ModuleUnpacker
/** /**
* 解包模块 * 解包模块
* @param bool $ignore_depends *
* @param mixed $ignore_depends
* @throws ModulePackException * @throws ModulePackException
* @throws ZMException * @throws ZMException
*/ */
@@ -61,7 +62,8 @@ class ModuleUnpacker
/** /**
* 检查模块依赖关系 * 检查模块依赖关系
* @param bool $ignore_depends *
* @param mixed $ignore_depends
* @throws ModulePackException * @throws ModulePackException
* @throws ZMException * @throws ZMException
*/ */
@@ -125,8 +127,8 @@ class ModuleUnpacker
throw new ModulePackException(zm_internal_errcode('E00068')); throw new ModulePackException(zm_internal_errcode('E00068'));
} }
$composer = json_decode(file_get_contents($composer_file), true); $composer = json_decode(file_get_contents($composer_file), true);
if (isset($this->module_config['composer-extend-autoload'])) { if (isset($this->module_config['unpack']['composer-autoload-items'])) {
$autoload = $this->module_config['composer-extend-autoload']; $autoload = $this->module_config['unpack']['composer-autoload-items'];
if (isset($autoload['psr-4'])) { if (isset($autoload['psr-4'])) {
Console::info('Adding extended autoload psr-4 for composer'); Console::info('Adding extended autoload psr-4 for composer');
$composer['autoload']['psr-4'] = isset($composer['autoload']['psr-4']) ? array_merge($composer['autoload']['psr-4'], $autoload['psr-4']) : $autoload['psr-4']; $composer['autoload']['psr-4'] = isset($composer['autoload']['psr-4']) ? array_merge($composer['autoload']['psr-4'], $autoload['psr-4']) : $autoload['psr-4'];
@@ -136,6 +138,7 @@ class ModuleUnpacker
$composer['autoload']['files'] = isset($composer['autoload']['files']) ? array_merge($composer['autoload']['files'], $autoload['files']) : $autoload['files']; $composer['autoload']['files'] = isset($composer['autoload']['files']) ? array_merge($composer['autoload']['files'], $autoload['files']) : $autoload['files'];
} }
} }
if (isset($this->module_config['composer-extend-require'])) { if (isset($this->module_config['composer-extend-require'])) {
foreach ($this->module_config['composer-extend-require'] as $k => $v) { foreach ($this->module_config['composer-extend-require'] as $k => $v) {
Console::info('Adding extended required composer library: ' . $k); Console::info('Adding extended required composer library: ' . $k);

View File

@@ -20,13 +20,14 @@ try {
$base_path = DataProvider::getSourceRootDir(); $base_path = DataProvider::getSourceRootDir();
$scan_paths = []; $scan_paths = [];
$composer = json_decode(file_get_contents($base_path . '/composer.json'), true); $composer = json_decode(file_get_contents($base_path . '/composer.json'), true);
$exclude_annotations = array_merge($composer['extra']['exclude_annotate'] ?? [], $composer['extra']['zm']['exclude-annotation-path'] ?? []);
foreach (($composer['autoload']['psr-4'] ?? []) as $k => $v) { foreach (($composer['autoload']['psr-4'] ?? []) as $k => $v) {
if (is_dir($base_path . '/' . $v) && !in_array($v, $composer['extra']['exclude_annotate'] ?? [])) { if (is_dir($base_path . '/' . $v) && !in_array($v, $exclude_annotations)) {
$scan_paths[trim($k, '\\')] = $base_path . '/' . $v; $scan_paths[trim($k, '\\')] = $base_path . '/' . $v;
} }
} }
foreach (($composer['autoload-dev']['psr-4'] ?? []) as $k => $v) { foreach (($composer['autoload-dev']['psr-4'] ?? []) as $k => $v) {
if (is_dir($base_path . '/' . $v) && !in_array($v, $composer['extra']['exclude_annotate'] ?? [])) { if (is_dir($base_path . '/' . $v) && !in_array($v, $exclude_annotations)) {
$scan_paths[trim($k, '\\')] = $base_path . '/' . $v; $scan_paths[trim($k, '\\')] = $base_path . '/' . $v;
} }
} }