This repository was archived by the owner on Feb 6, 2020. It is now read-only.
Detect cyclic dependency using reflection abstract factory#261
Open
asgrim wants to merge 2 commits into
Open
Conversation
…flectionBasedAbstractFactory
…r cyclic dependencies in ReflectionBasedAbstractFactory
Member
|
@asgrim Is this still a WIP? I've scheduled for 3.4.0, but if it's not ready, I'll wait... |
Member
|
Given the hacky nature of this, I wouldn't merge it at all, to be honest... |
Member
|
This repository has been closed and moved to laminas/laminas-servicemanager; a new issue has been opened at laminas/laminas-servicemanager#13. |
Member
|
This repository has been moved to laminas/laminas-servicemanager. If you feel that this patch is still relevant, please re-open against that repository, and reference this issue. To re-open, we suggest the following workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a new feature whereby cyclic dependencies are detected in a bit of an edge case. Example illustrated here: https://gist.github.com/asgrim/72f3ee4c25b901ffed58501657ea98da
I've written the test which demonstrates what I'm trying to do, but the implementation I feel is really sub-par however. My plan to implement was simply to check if
$requestedName === $type(i.e. the requested service name is the same as the parameter type being used), but in practice this doesn't work because$requestedNameis actually the resolved name:https://github.com/zendframework/zend-servicemanager/blob/develop/src/ServiceManager.php#L209-L222
On L209 the alias is resolved, and on L222
doCreateis called with the$resolvedNameso we never have the actual originally requested service name.Therefore the only solution I could come up with for now was to check if the
$containeris aServiceManagerand reverse-engineer the service name to the original alias. Really not keen on this though, but I'm lacking on any better ideas. Feedback welcome here! 👍It's worth adding that in real terms, this is a user error, but I just wanted to catch this situation and provide some useful feedback (instead of something unclear
Maximum function nesting level of '500' reached, aborting!), so if there's not a practical way to solve this problem, it simply may not be worth the effort.