Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

[ServiceManager] Implemented circular alias reference detection #5100

Closed
wants to merge 5 commits into from
Closed

[ServiceManager] Implemented circular alias reference detection #5100

wants to merge 5 commits into from

Conversation

tux-rampage
Copy link
Contributor

ServiceManagers that allow overwriting the service definition may
contain circular references which will cause an infinite loop.

I extracted the alias resolving code to a protected method that will detect
circular references and throw an exception if one is encountered.

ServiceManagers that allow overwriting the service definition may
contain circular references which will cause an infinite loop. 
Extracted alias resolving code to a protected method that will detect
circular references.
@Ocramius
Copy link
Member

@tux-rampage wouldn't it be easier to handle this kind of logic in setAlias?

@@ -810,4 +810,25 @@ public function testUsesMultipleDelegates()
$this->assertInstanceOf('stdClass', array_shift($fooDelegator->instances));
$this->assertSame($fooDelegator, array_shift($barDelegator->instances));
}

/**
* @covers Zend\ServiceMnager\ServiceManager::resolveAlias
Copy link
Contributor

Choose a reason for hiding this comment

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

typo ServiceMnager instead of ServiceManager, miss 'a' after 'M'

@tux-rampage
Copy link
Contributor Author

@Ocramius Might need to think about it. It's not as easy as putting it in the resolve logics. We should also keep in mind that $aliases is a protected and not a private member. So derived classes may manipulate it aside from setAlias().

@tux-rampage
Copy link
Contributor Author

@Ocramius It might be doable in the setAlias() method a s well, but I'm a bit concerned about performance when users start to add a lot of aliases. Any toughts?

@tux-rampage
Copy link
Contributor Author

@Ocramius I added a cycle check to setAlias() as well and modified the unit test accordingly

@ghost ghost assigned weierophinney Oct 22, 2013
weierophinney added a commit that referenced this pull request Oct 22, 2013
[ServiceManager] Implemented circular alias reference detection
weierophinney added a commit that referenced this pull request Oct 22, 2013
- one argument per line (sprintf call)
weierophinney added a commit that referenced this pull request Oct 22, 2013
weierophinney added a commit to zendframework/zend-servicemanager that referenced this pull request May 15, 2015
…sm-cyclic-alias-ref

[ServiceManager] Implemented circular alias reference detection
weierophinney added a commit to zendframework/zend-servicemanager that referenced this pull request May 15, 2015
- one argument per line (sprintf call)
weierophinney added a commit to zendframework/zend-servicemanager that referenced this pull request May 15, 2015
weierophinney added a commit to zendframework/zend-servicemanager that referenced this pull request May 15, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants