@@ -78,15 +78,8 @@ public static function createResourceForClass(\ReflectionClass $reflectionClass)
78
78
$ metadata ['__construct ' ] = self ::getResourceMetadataForMethod ($ constructor );
79
79
}
80
80
81
- // todo - when #17608 is merged, could refactor to private function to remove duplication
82
- // of determining valid "setter" methods
83
- foreach ($ reflectionClass ->getMethods (\ReflectionMethod::IS_PUBLIC ) as $ reflectionMethod ) {
84
- $ name = $ reflectionMethod ->getName ();
85
- if ($ reflectionMethod ->isStatic () || 1 !== $ reflectionMethod ->getNumberOfParameters () || 0 !== strpos ($ name , 'set ' )) {
86
- continue ;
87
- }
88
-
89
- $ metadata [$ name ] = self ::getResourceMetadataForMethod ($ reflectionMethod );
81
+ foreach (self ::getSetters ($ reflectionClass ) as $ reflectionMethod ) {
82
+ $ metadata [$ reflectionMethod ->name ] = self ::getResourceMetadataForMethod ($ reflectionMethod );
90
83
}
91
84
92
85
return new AutowireServiceResource ($ reflectionClass ->name , $ reflectionClass ->getFileName (), $ metadata );
@@ -119,13 +112,10 @@ private function completeDefinition($id, Definition $definition)
119
112
$ methodsCalled [$ methodCall [0 ]] = true ;
120
113
}
121
114
122
- foreach ($ reflectionClass ->getMethods (\ReflectionMethod::IS_PUBLIC ) as $ reflectionMethod ) {
123
- $ name = $ reflectionMethod ->getName ();
124
- if (isset ($ methodsCalled [$ name ]) || $ reflectionMethod ->isStatic () || 1 !== $ reflectionMethod ->getNumberOfParameters () || 0 !== strpos ($ name , 'set ' )) {
125
- continue ;
115
+ foreach (self ::getSetters ($ reflectionClass ) as $ reflectionMethod ) {
116
+ if (!isset ($ methodsCalled [$ reflectionMethod ->name ])) {
117
+ $ this ->autowireMethod ($ id , $ definition , $ reflectionMethod , false );
126
118
}
127
-
128
- $ this ->autowireMethod ($ id , $ definition , $ reflectionMethod , false );
129
119
}
130
120
}
131
121
@@ -386,6 +376,20 @@ private function addServiceToAmbiguousType($id, $type)
386
376
$ this ->ambiguousServiceTypes [$ type ][] = $ id ;
387
377
}
388
378
379
+ /**
380
+ * @param \ReflectionClass $reflectionClass
381
+ *
382
+ * @return \ReflectionMethod[]
383
+ */
384
+ private static function getSetters (\ReflectionClass $ reflectionClass )
385
+ {
386
+ foreach ($ reflectionClass ->getMethods (\ReflectionMethod::IS_PUBLIC ) as $ reflectionMethod ) {
387
+ if (!$ reflectionMethod ->isStatic () && 1 === $ reflectionMethod ->getNumberOfParameters () && 0 === strpos ($ reflectionMethod ->name , 'set ' )) {
388
+ yield $ reflectionMethod ;
389
+ }
390
+ }
391
+ }
392
+
389
393
private static function getResourceMetadataForMethod (\ReflectionMethod $ method )
390
394
{
391
395
$ methodArgumentsMetadata = array ();
0 commit comments