Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Remove example of register a service where its id match to its class #10070

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

Merged

Conversation

l-vo
Copy link
Contributor

@l-vo l-vo commented Jul 15, 2018

ResolveClassPass which resolve service definitions where class match to the service id is one of the first compiler pass processed (priority 100 in beforeOptimizationPasses phase). When adding a custom compiler pass, it is by default added to the beforeOptimizationPasses but with the default priority of 0. So the ResolveClassPass has already been executed and our custom service definition class isn't resolved.

@javiereguiluz
Copy link
Member

@l-vo thanks for your contribution. Sadly I'm having some problems trying to understand the issue here. Are you saying that the current code won't work? That the current code is unnecessary? thanks!

@l-vo
Copy link
Contributor Author

l-vo commented Jul 19, 2018

@javiereguiluz I think this code won't work in most cases. When the second argument of register isn't set, it's the compiler pass ResolveClassPass which inject the right class if the service id matchs with a class name. The problem is that ResolveClassPass is processed very early in the container compilation (see Symfony\Component\DependencyInjection\Compiler\PassConfig).

If I use $container->register(\AppBundle\NumberGenerator::class); in a compiler pass, ResolveClassPass is processed before my own compiler pass and my service class stay not resolved.

Is it clearer ?

@javiereguiluz
Copy link
Member

@l-vo it's more clear now. Thanks!

But before merging, let me ask our biggest expert in Dependency Injection to verify this change: @nicolas-grekas Thanks!

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Jul 24, 2018

I'm fine with this change, calling register can also be done in regular php definition of services, but nobody does that, so that the most common place to do this is in a compiler pass indeed.

@javiereguiluz
Copy link
Member

@l-vo thanks for fixing this error and for the detailed explanations. Also, congrats on your first Symfony Docs contribution!

@javiereguiluz javiereguiluz merged commit 4905190 into symfony:3.4 Jul 30, 2018
javiereguiluz added a commit that referenced this pull request Jul 30, 2018
…to its class (l-vo)

This PR was merged into the 3.4 branch.

Discussion
----------

Remove example of register a service where its id match to its class

`ResolveClassPass` which resolve service definitions where class match to the service id is one of the first compiler pass processed (priority 100 in beforeOptimizationPasses phase). When adding a custom compiler pass, it is by default added to the beforeOptimizationPasses but with the default priority of 0. So the `ResolveClassPass` has already been executed and our custom service definition class isn't resolved.

Commits
-------

4905190 Remove example of register a service where its id match to its class
@l-vo
Copy link
Contributor Author

l-vo commented Jul 30, 2018

@javiereguiluz You're welcome ! Thanks :-))

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

Successfully merging this pull request may close these issues.

4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.