Skip to content

修复 Ergodic 注解的插入顺序 #366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/ZM/Annotation/AnnotationParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ class_annotations: [
}
}
*/

// 保留ergodic注解
$append_ergodics = [];
// 保存对class的注解
$reflection_tree[$v]['class_annotations'] = $class_annotations;
// 保存类成员的方法的对应反射对象们
Expand All @@ -153,6 +154,9 @@ class_annotations: [
foreach ($reflection_tree[$v]['class_annotations'] as $vs) {
$vs->class = $v;

if (in_array($vs::class, $conf['name'])) {
continue;
}
// 预处理0:排除所有非继承于 AnnotationBase 的注解
if (!$vs instanceof AnnotationBase) {
logger()->notice($vs::class . ' is not extended from ' . AnnotationBase::class);
Expand All @@ -165,7 +169,8 @@ class_annotations: [
// 用 clone 的目的是生成个独立的对象,避免和 class 以及方法之间互相冲突
$copy = clone $vs;
$copy->method = $method->getName();
$reflection_tree[$v]['methods_annotations'][$method->getName()][] = $copy;
$append_ergodics[$method->getName()][] = $copy;
// $reflection_tree[$v]['methods_annotations'][$method->getName()][] = $copy;
$annotation_list[get_class($vs)][] = $copy;
}
// 标记为 Ergodic 的类注解,不作为类的注解解析,而是全部当作每个方法有注解,所以直接跳过
Expand All @@ -187,10 +192,19 @@ class_annotations: [
$vs->group = array_merge($vs->group, $this->class_bind_group_list[get_class($vs)]);
}
}
// 预处理:将Class的ergodic注解拼接到每个方法的注解列表前面,且按照顺序(修复 #365)
foreach ($reflection_tree[$v]['methods_annotations'] as $method_name => $annos) {
if (isset($append_ergodics[$method_name])) {
$reflection_tree[$v]['methods_annotations'][$method_name] = array_merge($append_ergodics[$method_name], $annos);
}
}

// 预处理3:处理每个函数上面的特殊注解,就是需要操作一些东西的
foreach (($reflection_tree[$v]['methods_annotations'] ?? []) as $method_name => $methods_annotations) {
foreach ($methods_annotations as $method_anno) {
if (in_array($method_anno::class, $conf['name'])) {
continue;
}
// 预处理3.0:排除所有非继承于 AnnotationBase 的注解
if (!$method_anno instanceof AnnotationBase) {
logger()->notice('Binding annotation ' . $method_anno::class . ' to ' . $v . '::' . $method_name . ' is not extended from ' . AnnotationBase::class);
Expand Down
2 changes: 1 addition & 1 deletion src/ZM/Framework.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Framework
public const VERSION_ID = 722;

/** @var string 版本名称 */
public const VERSION = '3.2.2';
public const VERSION = '3.2.3';

/**
* @var RuntimePreferences 运行时偏好(环境信息&参数)
Expand Down