-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DI] Allow get available services from service locator #23915
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
Conversation
c47ffc3
to
4993b1c
Compare
This is a nice addition to ease debugging I suppose. I just don't think this is how you should handle these errors runtime though, might want to solve it without service locator? |
Service locator is needed here. |
Thank you @Koc. |
… (Koc) This PR was merged into the 3.4 branch. Discussion ---------- [DI] Allow get available services from service locator | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - <!-- - Bug fixes must be submitted against the lowest branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against the 3.4, legacy code removals go to the master branch. - Please fill in this template according to the PR you're about to submit. - Replace this comment by a description of what your PR is solving. --> Sometimes we are using service locators and throw context specific exceptions if service not found inside it. Would be nice inform user about available services in our custom exception, like: ```php try { return $this->transports->get($transport); } catch (NotFoundExceptionInterface $e) { $availableTransports = method_exists($e, 'getAlternatives') ? $e->getAlternatives() : []; throw TransportNotFoundException::create($transport, $availableTransports, $e); } ``` Commits ------- 4993b1c Allow to get alternatives when ServiceNotFoundException occurs.
Sometimes we are using service locators and throw context specific exceptions if service not found inside it. Would be nice inform user about available services in our custom exception, like: