@@ -78,15 +78,8 @@ public static function createResourceForClass(\ReflectionClass $reflectionClass)
7878 $ metadata ['__construct ' ] = self ::getResourceMetadataForMethod ($ constructor );
7979 }
8080
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 );
9083 }
9184
9285 return new AutowireServiceResource ($ reflectionClass ->name , $ reflectionClass ->getFileName (), $ metadata );
@@ -119,13 +112,10 @@ private function completeDefinition($id, Definition $definition)
119112 $ methodsCalled [$ methodCall [0 ]] = true ;
120113 }
121114
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 );
126118 }
127-
128- $ this ->autowireMethod ($ id , $ definition , $ reflectionMethod , false );
129119 }
130120 }
131121
@@ -386,6 +376,20 @@ private function addServiceToAmbiguousType($id, $type)
386376 $ this ->ambiguousServiceTypes [$ type ][] = $ id ;
387377 }
388378
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+
389393 private static function getResourceMetadataForMethod (\ReflectionMethod $ method )
390394 {
391395 $ methodArgumentsMetadata = array ();
0 commit comments