Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you keep this comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the comment then :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved.

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());
}

/**
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -317,13 +318,21 @@ interface EInterface extends DInterface
{
}

class F implements EInterface
interface IInterface
{
}

class I implements IInterface
{
}

class F extends I implements EInterface
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you also needs the case of an interface extending another interface (and the class implementing the child one), to be sure it works fine too

{
}

class G
{
public function __construct(DInterface $d, EInterface $e)
public function __construct(DInterface $d, EInterface $e, IInterface $i)
{
}
}
Expand Down