Thanks to visit codestin.com
Credit goes to github.com

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 @@ -993,8 +993,15 @@ public function findDefinition($id)
{
$id = $this->normalizeId($id);

$seen = array();
while (isset($this->aliasDefinitions[$id])) {
$id = (string) $this->aliasDefinitions[$id];

if (isset($seen[$id])) {
throw new ServiceCircularReferenceException($id, array_keys($seen));
Copy link
Member

Choose a reason for hiding this comment

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

The message should be improved see the CheckCircularReferencePass

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean?

Copy link
Member

@nicolas-grekas nicolas-grekas Dec 7, 2017

Choose a reason for hiding this comment

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

Sorry was on mobile :)
This is what I mean:

if (isset($seen[$id])) {
    $seen = array_slice($seen, array_search($id, $seen));
    $seen[] = $id;

    throw new ServiceCircularReferenceException($id, $seen);
}

$seen[$id] = $id;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see the idea. Tho, we can't use array_slice with string keys in an array, we'll have to use 2 of them.

}

$seen[$id] = true;
}

return $this->getDefinition($id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,22 @@ public function testInlinedDefinitions()
$this->assertNotSame($bar->foo, $barUser->foo);
}

/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
* @expectedExceptionMessage Circular reference detected for service "app.test_class", path: "app.test_class -> App\TestClass".
*/
public function testThrowsCircularExceptionForCircularAliases()
{
$builder = new ContainerBuilder();

$builder->setAliases(array(
'app.test_class' => new Alias('App\\TestClass'),
'App\\TestClass' => new Alias('app.test_class'),
));

$builder->findDefinition('App\\TestClass');
}

public function testInitializePropertiesBeforeMethodCalls()
{
$container = new ContainerBuilder();
Expand Down