10000 [DI Debug] Private Aliases not shown with debug:container · Issue #16388 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[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

Closed
linaori opened this issue Oct 30, 2015 · 8 comments
Closed

[DI Debug] Private Aliases not shown with debug:container #16388

linaori opened this issue Oct 30, 2015 · 8 comments

Comments

@linaori
Copy link
Contributor
linaori commented Oct 30, 2015

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 where clients is the entity manager (connection) name. This would result in a private alias: order.repository.order_line pointing at order.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 in TextDescriptor::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.

@linaori
Copy link
Contributor Author
linaori commented Nov 12, 2015

Update, RemovePrivateAliasesPass is the one removing the aliases, which is quite frankly, really annoying in development. It doesn't remove public aliases, just the private ones.

Is there a way to keep those aliases so I can find back which ones are available?

@TomasVotruba
Copy link
Contributor

What needs to be done here?

@javiereguiluz
Copy link
Member

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 removePrivateAliasesPass in dev because we want to minimize the differences in the container built for dev and prod).

@nicolas-grekas
Copy link
Member
nicolas-grekas commented Oct 26, 2016

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)

@jeremyFreeAgent
Copy link
Contributor

@nicolas-grekas That will also help to have the real name of the private services. I like that.

fabpot added a commit that referenced this issue Apr 11, 2017
…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()
symfony-splitter pushed a commit to symfony/framework-bundle that referenced this issue Apr 11, 2017
…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()
@chalasr
Copy link
Member
chalasr commented Apr 11, 2017

See #22385

@stof
Copy link
Member
stof commented Apr 12, 2017

@nicolas-grekas not running compiler passes is not an option. Compiler passes can also create services (and alter dependencies between them).
We would need to disable only the removing pass.

@chalasr
Copy link
Member
chalasr commented Apr 12, 2017

@stof that's what #22385 does.

fabpot added a commit that referenced this issue May 3, 2017
…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
-------

![before](http://image.prntscr.com/image/2a69485a4a764316a90260b4e3dfc2a2.png)

After
------

![after](http://image.prntscr.com/image/ea42daa0e5c94841a28dd256450dc8ef.png)

Commits
-------

883723e Show private aliases in debug:container
@fabpot fabpot closed this as completed May 3, 2017 7945
symfony-splitter pushed a commit to symfony/framework-bundle that referenced this issue May 3, 2017
…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
-------

![before](http://image.prntscr.com/image/2a69485a4a764316a90260b4e3dfc2a2.png)

After
------

![after](http://image.prntscr.com/image/ea42daa0e5c94841a28dd256450dc8ef.png)

Commits
-------

883723ef53 Show private aliases in debug:container
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

9 participants
0