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

Untraceable private aliases #618

Closed
linaori opened this issue Nov 12, 2015 · 2 comments
Closed

Untraceable private aliases #618

linaori opened this issue Nov 12, 2015 · 2 comments
Labels

Comments

@linaori
Copy link

linaori commented Nov 12, 2015

Currently it's impossible to trace back private aliases. They are made private so everything is optimized away if neither the service nor alias is used. The problem is that the RemovePrivateAliasPass always removes them. I've created the issue symfony/symfony#16388 but I don't think this will be fixed as it's a development exception.

I know it's impossible to (also due to performance) to analyze all the loaded files and extensions. However, I found this log entry which is added when compiling: Symfony\Component\DependencyInjection\Compiler\RemovePrivateAliasesPass: Removed service "contract.repository.contract"; reason: private alias

I found it back in: var/cache/dev/appDevDebugProjectContainerCompiler.log (using var instead of app for the cache). With some simple parsing, all private aliases could be retrieved from here and would make it a lot easier to develop with private aliases.

In my case we have a lot of private aliases, 1 per entity repository. We have about 100 entities spread over several packages (not bundles). We have 1 bundle that dynamically creates the repository definitions based on the connection name and adds an alias (default format) so you can always change the connection without breaking your app. As said, they are private for performance reasons.


Maybe a whole different idea could be to let users add log parsers with a regex to filter out their own services? I know it's not possible to retrieve their parameters/class, but at least having a list to choose from would be very welcome!

Some nice example messages that could be parsed:

  • Symfony\Component\DependencyInjection\Compiler\InlineServiceDefinitionsPass: Inlined service "controller_resolver" to "debug.controller_resolver".
  • Symfony\Component\DependencyInjection\Compiler\ReplaceAliasByActualDefinitionPass: Changed reference of service "twig" previously pointing to "twig.loader.filesystem" to "twig.loader".
  • Symfony\Component\DependencyInjection\Compiler\RemoveUnusedDefinitionsPass: Removed service "templating.finder"; reason: unused
fabpot added a commit to symfony/symfony 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
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
@chalasr
Copy link

chalasr commented May 3, 2017

symfony/symfony#22385 has been merged, this should be resolved.

Haehnchen added a commit that referenced this issue Jun 3, 2017
… safety for Symfony 3.3 private service debugger #618 #943
Haehnchen added a commit that referenced this issue Jun 3, 2017
… safety for Symfony 3.3 private service debugger #618 #943
@Haehnchen Haehnchen added the fixed label Jun 3, 2017
@Haehnchen
Copy link
Owner

some optimizations done, should now work more smoothly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants