File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed
src/Symfony/Component/DependencyInjection Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -138,11 +138,17 @@ private function populateAvailableTypes()
138
138
*/
139
139
private function populateAvailableType ($ id , Definition $ definition )
140
140
{
141
+ // Never use abstract services
142
+ if ($ definition ->isAbstract ()) {
143
+ return ;
144
+ }
145
+
141
146
foreach ($ definition ->getAutowiringTypes () as $ type ) {
142
147
$ this ->definedTypes [$ type ] = true ;
143
148
$ this ->types [$ type ] = $ id ;
144
149
}
145
150
151
+ // Cannot use reflection if the class isn't set
146
152
if (!$ definition ->getClass ()) {
147
153
return ;
148
154
}
Original file line number Diff line number Diff line change @@ -216,6 +216,21 @@ public function testClassNotFoundThrowsException()
216
216
$ pass = new AutowirePass ();
217
217
$ pass ->process ($ container );
218
218
}
219
+
220
+ public function testDontUseAbstractServices ()
221
+ {
222
+ $ container = new ContainerBuilder ();
223
+
224
+ $ container ->register ('abstract_foo ' , __NAMESPACE__ .'\Foo ' )->setAbstract (true );
225
+ $ container ->register ('foo ' , __NAMESPACE__ .'\Foo ' );
226
+ $ container ->register ('bar ' , __NAMESPACE__ .'\Bar ' )->setAutowired (true );
227
+
228
+ $ pass = new AutowirePass ();
229
+ $ pass ->process ($ container );
230
+
231
+ $ arguments = $ container ->getDefinition ('bar ' )->getArguments ();
232
+ $ this ->assertSame ('foo ' , (string ) $ arguments [0 ]);
233
+ }
219
234
}
220
235
221
236
class Foo
You can’t perform that action at this time.
0 commit comments