Skip to content

Untraceable private aliases #618

Closed
Closed
@linaori

Description

@linaori

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions