13
13
*/
14
14
class ClassAttributeCollector
15
15
{
16
- private ParameterAttributeCollector $ parameterAttributeCollector ;
17
-
18
16
public function __construct (
19
17
private Logger $ log ,
20
18
) {
21
- $ this ->parameterAttributeCollector = new ParameterAttributeCollector ($ this ->log );
22
19
}
23
20
24
21
/**
@@ -126,8 +123,6 @@ private static function isAttributeIgnored(ReflectionAttribute $attribute): bool
126
123
/**
127
124
* @param array<TransientTargetMethod> $methodAttributes
128
125
* @param array<TransientTargetParameter> $parameterAttributes
129
- *
130
- * @return void
131
126
*/
132
127
private function collectMethodAndParameterAttributes (
133
128
string $ class ,
@@ -153,7 +148,41 @@ private function collectMethodAndParameterAttributes(
153
148
154
149
$ parameterAttributes = array_merge (
155
150
$ parameterAttributes ,
156
- $ this ->parameterAttributeCollector -> collectAttributes ($ methodReflection ),
151
+ $ this ->collectParameterAttributes ($ methodReflection ),
157
152
);
158
153
}
154
+
155
+ /**
156
+ * @return array<TransientTargetParameter>
157
+ */
158
+ private function collectParameterAttributes (\ReflectionMethod $ reflectionFunctionAbstract ): array
159
+ {
160
+ $ targets = [];
161
+ $ class = $ reflectionFunctionAbstract ->class ;
162
+ $ method = $ reflectionFunctionAbstract ->name ;
163
+
164
+ foreach ($ reflectionFunctionAbstract ->getParameters () as $ parameter ) {
165
+ /** @var non-empty-string $name */
166
+ $ name = $ parameter ->name ;
167
+
168
+ $ paramLabel = $ class . ':: ' . $ method . '( ' . $ name . ') ' ;
169
+
170
+ foreach ($ parameter ->getAttributes () as $ attribute ) {
171
+ if (self ::isAttributeIgnored ($ attribute )) {
172
+ continue ;
173
+ }
174
+
175
+ $ this ->log ->debug ("Found attribute {$ attribute ->getName ()} on $ paramLabel " );
176
+
177
+ $ targets [] = new TransientTargetParameter (
178
+ $ attribute ->getName (),
179
+ $ attribute ->getArguments (),
180
+ $ method ,
181
+ $ name
182
+ );
183
+ }
184
+ }
185
+
186
+ return $ targets ;
187
+ }
159
188
}
0 commit comments