@@ -120,14 +120,22 @@ private function completeDefinition($id, Definition $definition, array $autowire
120
120
*
121
121
* @param string $id
122
122
* @param \ReflectionClass $reflectionClass
123
- * @param string[] $autowiredMethods
123
+ * @param string[] $configuredAutowiredMethods
124
124
*
125
125
* @return \ReflectionMethod[]
126
126
*/
127
- private function getMethodsToAutowire ($ id , \ReflectionClass $ reflectionClass , array $ autowiredMethods )
127
+ private function getMethodsToAutowire ($ id , \ReflectionClass $ reflectionClass , array $ configuredAutowiredMethods )
128
128
{
129
129
$ found = array ();
130
130
$ regexList = array ();
131
+
132
+ // Always try to autowire the constructor
133
+ if (in_array ('__construct ' , $ configuredAutowiredMethods , true )) {
134
+ $ autowiredMethods = $ configuredAutowiredMethods ;
135
+ } else {
136
+ $ autowiredMethods = array_merge (array ('__construct ' ), $ configuredAutowiredMethods );
137
+ }
138
+
131
139
foreach ($ autowiredMethods as $ pattern ) {
132
140
$ regexList [] = '/^ ' .str_replace ('\* ' , '.* ' , preg_quote ($ pattern , '/ ' )).'$/i ' ;
133
141
}
@@ -147,7 +155,7 @@ private function getMethodsToAutowire($id, \ReflectionClass $reflectionClass, ar
147
155
}
148
156
}
149
157
150
- if ($ notFound = array_diff ($ autowiredMethods , $ found )) {
158
+ if ($ notFound = array_diff ($ configuredAutowiredMethods , $ found )) {
151
159
$ compiler = $ this ->container ->getCompiler ();
152
160
$ compiler ->addLogMessage ($ compiler ->getLoggingFormatter ()->formatUnusedAutowiringPatterns ($ this , $ id , $ notFound ));
153
161
}
0 commit comments