Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect cyclic dependency using reflection abstract factory #13

Closed
weierophinney opened this issue Dec 31, 2019 · 3 comments
Closed

Detect cyclic dependency using reflection abstract factory #13

weierophinney opened this issue Dec 31, 2019 · 3 comments

Comments

@weierophinney
Copy link
Member

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 $requestedName is 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 doCreate is called with the $resolvedName so 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 $container is a ServiceManager and 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.


Originally posted by @asgrim at zendframework/zend-servicemanager#261

@weierophinney
Copy link
Member Author

@asgrim Is this still a WIP? I've scheduled for 3.4.0, but if it's not ready, I'll wait...


Originally posted by @weierophinney at zendframework/zend-servicemanager#261 (comment)

@weierophinney
Copy link
Member Author

Given the hacky nature of this, I wouldn't merge it at all, to be honest...


Originally posted by @Ocramius at zendframework/zend-servicemanager#261 (comment)

@GeeH
Copy link
Contributor

GeeH commented Jun 8, 2020

Closing after conversation with @asgrim. Thank you so much for the inital work.

@GeeH GeeH closed this as completed Jun 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants