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

Skip to content

Add an option to debug:container CLI command to see service usage #37413

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

Closed
matks opened this issue Jun 25, 2020 · 5 comments · Fixed by #38903
Closed

Add an option to debug:container CLI command to see service usage #37413

matks opened this issue Jun 25, 2020 · 5 comments · Fixed by #38903
Labels
DependencyInjection Feature Help wanted Issues and PRs which are looking for volunteers to complete them. Stalled

Comments

@matks
Copy link

matks commented Jun 25, 2020

Description

Quite often, I find myself in a situation where I need to update an existing Service in my Symfony application and I need to find "all the services relying on it" to update them.

So I have service app.category.data_provider and I want to see all other services that are being injected this instance.

So I would like this to happen:

$ php bin/console debug:container app.category.data_provider --show-usage

Information for Service "app.category.data_provider"
======================================================================

 ---------------- -----------------------------------------------------------------------
  Option           Value
 ---------------- -----------------------------------------------------------------------
  Service ID    app.category.data_provider
  Class            App\Category\Data_provider
  Tags             -
  Public           yes
  Synthetic     no
  Lazy             no
  Shared         yes
  Abstract       no
  Autowired        no
  Autoconfigured   no
  Used by:              app.category.data_handler, app.product.registrar
 ---------------- -----------------------------------------------------------------------

I think about making it optional because I expect the operation to be resources consuming, so no need to clutter the default debug:container Command with it.

I have an idea about how to do it, but it's an expensive one: go through the full container graph and look for all declarations 😅 . I'm checking whether or not the idea is good by opening this issue before diving into the code and submitting a PR.

If the application is leveraging the power of auto-wiring and strict typing, the "find usage" search can be done by any good IDE. However on legacy applications, auto-wiring and strict typing are not that common ...

@noniagriconomie
Copy link
Contributor

Once i used something like that
https://gist.github.com/sagikazarmark/4b52811c96e0fe6225022e038c7ccb9a
It may help found the relations for « older » app without strict type injection

@matks
Copy link
Author

matks commented Jun 26, 2020

Once i used something like that
https://gist.github.com/sagikazarmark/4b52811c96e0fe6225022e038c7ccb9a
It may help found the relations for « older » app without strict type injection

I used it too to generate a graph of the container 😄 to have a "big picture of the app structure" (PR here). Graphviz is amazing !

Initially I thought I would have to write a dumper myself, then I started typing the classname ... and my IDE told me there was a native GraphvizDumper inside Symfony 😁 (no idea what it's for but really useful)

@noniagriconomie
Copy link
Contributor

I used to dump the workflow for documentation purpose and one day I found this class for the container :)

For me, maybe a new command appart should be added to leverage this dumper/grapher like the https://symfony.com/doc/current/workflow/dumping-workflows.html, not the debug:container

And yes having the option to passe the fqdn or service id to only draw this service graph could be more precise :)

@chalasr chalasr added the Help wanted Issues and PRs which are looking for volunteers to complete them. label Oct 18, 2020
@carsonbot
Copy link

Thank you for this suggestion.
There has not been a lot of activity here for a while. Would you still like to see this feature?

@matks
Copy link
Author

matks commented Apr 19, 2021

If the application is leveraging the power of auto-wiring and strict typing, the "find usage" search can be done by any good IDE. However on legacy applications, auto-wiring and strict typing are not that common ...

Since strict typing is becoming standard, I think the need for this will fade in time. Let's close this issue and let Symfony contributors focus on topics with a better ROI.

@matks matks closed this as completed Apr 19, 2021
fabpot added a commit that referenced this issue Jul 16, 2022
…ut (Bert ter Heide, bertterheide)

This PR was squashed before being merged into the 6.2 branch.

Discussion
----------

[FrameworkBundle] Add "Usages" to debug:container output

| Q             | A
| ------------- | ---
| Branch?       | 6.2
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | Fix #37413
| License       | MIT

This feature adds "Usages" output to the debug:container command which allows a user to see which services require the requested service.

Commits
-------

e1ab83b [FrameworkBundle] Add "Usages" to debug:container output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DependencyInjection Feature Help wanted Issues and PRs which are looking for volunteers to complete them. Stalled
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants