@@ -30,17 +30,7 @@ protected function __handlePropertyHandler(string $className)
30
30
31
31
// Inject the properties of traits.
32
32
// Because the property annotations of trait couldn't be collected by class.
33
- $ traitNames = $ reflectionClass ->getTraitNames ();
34
- if (is_array ($ traitNames )) {
35
- foreach ($ traitNames ?? [] as $ traitName ) {
36
- $ traitProperties = ReflectionManager::reflectPropertyNames ($ traitName );
37
- $ traitProperties = array_diff ($ traitProperties , $ handled );
38
- $ handled = array_merge (
39
- $ handled ,
40
- $ this ->__handle ($ className , $ traitName , $ traitProperties )
41
- );
42
- }
43
- }
33
+ $ handled = $ this ->__handleTrait ($ reflectionClass , $ handled , $ className );
44
34
45
35
// Inject the properties of parent class.
46
36
// It can be used to deal with parent classes whose subclasses have constructor function, but don't execute `parent::__construct()`.
@@ -64,6 +54,26 @@ protected function __handlePropertyHandler(string $className)
64
54
}
65
55
}
66
56
57
+ protected function __handleTrait (\ReflectionClass $ reflectionClass , array $ handled , string $ className ): array
58
+ {
59
+ foreach ($ reflectionClass ->getTraits () ?? [] as $ reflectionTrait ) {
60
+ if (in_array ($ reflectionTrait ->getName (), [ProxyTrait::class, PropertyHandlerTrait::class])) {
61
+ continue ;
62
+ }
63
+ $ traitProperties = ReflectionManager::reflectPropertyNames ($ reflectionTrait ->getName ());
64
+ $ traitProperties = array_diff ($ traitProperties , $ handled );
65
+ if (! $ traitProperties ) {
66
+ continue ;
67
+ }
68
+ $ handled = array_merge (
69
+ $ handled ,
70
+ $ this ->__handle ($ className , $ reflectionTrait ->getName (), $ traitProperties )
71
+ );
72
+ $ handled = $ this ->__handleTrait ($ reflectionTrait , $ handled , $ className );
73
+ }
74
+ return $ handled ;
75
+ }
76
+
67
77
protected function __handle (string $ currentClassName , string $ targetClassName , array $ properties ): array
68
78
{
69
79
$ handled = [];
0 commit comments