-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DI Debug] Private Aliases not shown with debug:container #16388
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
Comments
Update, Is there a way to keep those aliases so I can find back which ones are available? |
What needs to be done here? |
My vote is for closing this issue as "won't fix". I can't see a simple way to implement this feature (we can't for example disable the |
Or, this command could recreate a container from loaders, and get private services from there, without running any compiler pass on this temporary container (that should be trashed once the command ends) |
@nicolas-grekas That will also help to have the real name of the private services. I like that. |
…ition() on aliases (chalasr) This PR was merged into the 3.3-dev branch. Discussion ---------- [FrameworkBundle] Use findDefinition() instead of getDefinition() on aliases | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a The services for which `has()` is called might be aliases at this point so `getDefinition()` gives an exception, I ran into by executing this pass but not the removing ones (skipping ReplaceAliasByActualDefinitionPass) while working on #16388. Let's make it safe to use independently. Commits ------- 41f3d1f Use findDefinition() instead of getDefinition() after calling has()
…ition() on aliases (chalasr) This PR was merged into the 3.3-dev branch. Discussion ---------- [FrameworkBundle] Use findDefinition() instead of getDefinition() on aliases | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a The services for which `has()` is called might be aliases at this point so `getDefinition()` gives an exception, I ran into by executing this pass but not the removing ones (skipping ReplaceAliasByActualDefinitionPass) while working on symfony/symfony#16388. Let's make it safe to use independently. Commits ------- 41f3d1f166 Use findDefinition() instead of getDefinition() after calling has()
See #22385 |
@nicolas-grekas not running compiler passes is not an option. Compiler passes can also create services (and alter dependencies between them). |
…ntainer (chalasr) This PR was merged into the 3.3-dev branch. Discussion ---------- [DX][FrameworkBundle] Show private aliases in debug:container | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #16388 Haehnchen/idea-php-symfony2-plugin#618 | License | MIT | Doc PR | n/a By building and compiling the container without `TYPE_REMOVING` passes, private aliases are available (shown when `--show-private` is passed). The ContainerBuilderDebugDumpPass now makes use of the ConfigCache component, removing the need for clearing the cache to get the debug:container output up to date (in sync with latest config). Config ------- ```yaml services: AppBundle\Foo: public: false foo_consumer1: class: AppBundle\Foo arguments: [ '@appbundle\Foo' ] foo_consumer2: class: AppBundle\Foo arguments: [ '@appbundle\Foo' ] foo_alias: alias: AppBundle\Foo foo_private_alias: public: false alias: AppBundle\Foo ``` Before -------  After ------  Commits ------- 883723e Show private aliases in debug:container
…ntainer (chalasr) This PR was merged into the 3.3-dev branch. Discussion ---------- [DX][FrameworkBundle] Show private aliases in debug:container | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony/symfony#16388 Haehnchen/idea-php-symfony2-plugin#618 | License | MIT | Doc PR | n/a By building and compiling the container without `TYPE_REMOVING` passes, private aliases are available (shown when `--show-private` is passed). The ContainerBuilderDebugDumpPass now makes use of the ConfigCache component, removing the need for clearing the cache to get the debug:container output up to date (in sync with latest config). Config ------- ```yaml services: AppBundle\Foo: public: false foo_consumer1: class: AppBundle\Foo arguments: [ '@appbundle\Foo' ] foo_consumer2: class: AppBundle\Foo arguments: [ '@appbundle\Foo' ] foo_alias: alias: AppBundle\Foo foo_private_alias: public: false alias: AppBundle\Foo ``` Before -------  After ------  Commits ------- 883723ef53 Show private aliases in debug:container
When running debug:container --show-private, it doesn't show private aliases. A scenario where this happens is when a private alias is used for a private service to optimize them away and prevent
Container->get()
usage.My company has code that automates generating services for repositories, this follows a specific setup:
order.repository.clients_order_line
whereclients
is the entity manager (connection) name. This would result in a private alias:order.repository.order_line
pointing atorder.repository.clients_order_line
. This code works perfect with one downside, private alias cannot be found back.The naming follows a convention so we can always find it back one way or another, but we cannot find it using the
debug:container
command nor can an IDE such as PHPStorm find it as it's optimized away. I've been digging in the code and inTextDescriptor::describeContainerServices()
this is not available.My guess is that private aliases are optimized away if they are not used before hitting this code and is therefore a bug. If I wanted to find all un-used private services/alias, I would be unable to do so with the current setup.
The text was updated successfully, but these errors were encountered: