[DependencyInjection] Autowing: exclude abstract definitons
This commit is contained in:
parent
71d502a174
commit
faefc6074f
@ -138,11 +138,17 @@ class AutowirePass implements CompilerPassInterface
|
|||||||
*/
|
*/
|
||||||
private function populateAvailableType($id, Definition $definition)
|
private function populateAvailableType($id, Definition $definition)
|
||||||
{
|
{
|
||||||
|
// Never use abstract services
|
||||||
|
if ($definition->isAbstract()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($definition->getAutowiringTypes() as $type) {
|
foreach ($definition->getAutowiringTypes() as $type) {
|
||||||
$this->definedTypes[$type] = true;
|
$this->definedTypes[$type] = true;
|
||||||
$this->types[$type] = $id;
|
$this->types[$type] = $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cannot use reflection if the class isn't set
|
||||||
if (!$definition->getClass()) {
|
if (!$definition->getClass()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -216,6 +216,21 @@ class AutowirePassTest extends \PHPUnit_Framework_TestCase
|
|||||||
$pass = new AutowirePass();
|
$pass = new AutowirePass();
|
||||||
$pass->process($container);
|
$pass->process($container);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDontUseAbstractServices()
|
||||||
|
{
|
||||||
|
$container = new ContainerBuilder();
|
||||||
|
|
||||||
|
$container->register('abstract_foo', __NAMESPACE__.'\Foo')->setAbstract(true);
|
||||||
|
$container->register('foo', __NAMESPACE__.'\Foo');
|
||||||
|
$container->register('bar', __NAMESPACE__.'\Bar')->setAutowired(true);
|
||||||
|
|
||||||
|
$pass = new AutowirePass();
|
||||||
|
$pass->process($container);
|
||||||
|
|
||||||
|
$arguments = $container->getDefinition('bar')->getArguments();
|
||||||
|
$this->assertSame('foo', (string) $arguments[0]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Foo
|
class Foo
|
||||||
|
Reference in New Issue
Block a user