diff --git a/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php b/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php index ec7880be89b95..67b9008423bb2 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php @@ -148,45 +148,17 @@ private function populateAvailableType($id, Definition $definition) $this->types[$type] = $id; } - // Cannot use reflection if the class isn't set - if (!$definition->getClass()) { + if (!$reflectionClass = $this->getReflectionClass($id, $definition)) { return; } - if ($reflectionClass = $this->getReflectionClass($id, $definition)) { - $this->extractInterfaces($id, $reflectionClass); - $this->extractAncestors($id, $reflectionClass); - } - } - - /** - * Extracts the list of all interfaces implemented by a class. - * - * @param string $id - * @param \ReflectionClass $reflectionClass - */ - private function extractInterfaces($id, \ReflectionClass $reflectionClass) - { - foreach ($reflectionClass->getInterfaces() as $interfaceName => $reflectionInterface) { - $this->set($interfaceName, $id); - - $this->extractInterfaces($id, $reflectionInterface); + foreach ($reflectionClass->getInterfaces() as $reflectionInterface) { + $this->set($reflectionInterface->name, $id); } - } - - /** - * Extracts all inherited types of a class. - * - * @param string $id - * @param \ReflectionClass $reflectionClass - */ - private function extractAncestors($id, \ReflectionClass $reflectionClass) - { - $this->set($reflectionClass->name, $id); - if ($reflectionParentClass = $reflectionClass->getParentClass()) { - $this->extractAncestors($id, $reflectionParentClass); - } + do { + $this->set($reflectionClass->name, $id); + } while ($reflectionClass = $reflectionClass->getParentClass()); } /** @@ -256,6 +228,7 @@ private function getReflectionClass($id, Definition $definition) return $this->reflectionClasses[$id]; } + // Cannot use reflection if the class isn't set if (!$class = $definition->getClass()) { return; } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php index f1ed72e94a4cd..28d6ab6339eea 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php @@ -61,9 +61,10 @@ public function testProcessAutowireInterface() $pass = new AutowirePass(); $pass->process($container); - $this->assertCount(2, $container->getDefinition('g')->getArguments()); + $this->assertCount(3, $container->getDefinition('g')->getArguments()); $this->assertEquals('f', (string) $container->getDefinition('g')->getArgument(0)); $this->assertEquals('f', (string) $container->getDefinition('g')->getArgument(1)); + $this->assertEquals('f', (string) $container->getDefinition('g')->getArgument(2)); } public function testCompleteExistingDefinition() @@ -317,13 +318,21 @@ interface EInterface extends DInterface { } -class F implements EInterface +interface IInterface +{ +} + +class I implements IInterface +{ +} + +class F extends I implements EInterface { } class G { - public function __construct(DInterface $d, EInterface $e) + public function __construct(DInterface $d, EInterface $e, IInterface $i) { } }