Repository navigation
fix(reflection): ReflectionAttribute 支持 std 注解 getArguments/newInstance - #21
Merged
Merged
Conversation
在类/方法/属性/参数上与应用实例并行存储 Annotation 声明节点, ReflectionAttribute 据此还原用户实参并在 newInstance 后绑定可读属性; 放宽对无 PHP #[Attribute] 元数据的 std 原生注解校验。 Co-authored-by: selden <ctfang@users.noreply.github.com>
恢复无 #[Attribute] 的 PHP 类报错,同时 std 原生注解类不经过该校验。 Co-authored-by: selden <ctfang@users.noreply.github.com>
带 target 形参的注解经 InstantiateAnnotationForReflection 绑定实参且不执行构造副作用; 修正 ReflectionAttribute 目标常量(PARAMETER=32);补充 Container/参数 target 回归测试。 Co-authored-by: selden <ctfang@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
根因(Loom 复测反馈)
newInstance():CreateInstanceFromClass只传入用户实参,未注入target;构造里annotationTargetClass在缺少下标 1 时把下标 0 的用户字符串当成$target,触发「target 类型错误」。ReflectionAttribute的metadata.target把TARGET_PARAMETER错设为16(实为TARGET_CLASS_CONSTANT),TARGET_PROPERTY|TARGET_PARAMETER等标志与参数反射的 target 对不上,误报 cannot target function。修复
bindAnnotationConstructorArgs,新增InstantiateAnnotationForReflection:按声明绑定用户实参 +decl.Target,不执行InitAnnotation/construct副作用。newInstance()对含AnnotationTargetParameter的注解类走该路径,并继续bindUserAnnotationProperties。Attribute::TARGET_*常量(TARGET_PARAMETER = 32),按目标类型生成校验错误信息。测试
go test ./node ./std/php/reflection -count=1 go run ./zy.go tests/php/reflection_attribute_args_test.php go run ./zy.go tests/php/function_attribute_contract_test.php覆盖:Singleton/Bind/Inject/Named
newInstance、构造参数上的InjectConfig(PROPERTY|PARAMETER)、仅 TARGET_FUNCTION 在参数上仍应失败。Loom 复测
在 frame-context 之上拉取本分支后,复跑
loom_modules_test、loom_config_injection_test与ModuleDiscovery::attribute()/newInstance()路径即可。