Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DependencyInjection] make the service container builder register its own self referencing definition #21627

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
merged 1 commit into from
Feb 28, 2017

Conversation

hhamon
Copy link
Contributor

@hhamon hhamon commented Feb 16, 2017

Q A
Branch? master
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets ~
License MIT
Doc PR ~

@hhamon
Copy link
Contributor Author

hhamon commented Feb 16, 2017

This PR fixes a bug in Symfony 3.3 that prevents autowiring compiler passes to autowire the service container in a service. The bug mostly occurs when you use setter methods autowiring when defining regular Symfony controller classes as services.

services:

    AppBundle\Controller\:
        resource: '../../src/AppBundle/Controller'
        autowire: ['get*', 'set*']

If the controller class still extends the base Symfony controller class (or implements the ContainerAwareInterface), the service container will be injected through the setContainer autowired method.

@hhamon hhamon force-pushed the fix-service-container-definition branch 2 times, most recently from a370b3f to fc66b28 Compare February 16, 2017 14:04
@hhamon
Copy link
Contributor Author

hhamon commented Feb 16, 2017

Looks like fabbot.io violations is a false positive due to a fixtures file,

@hhamon hhamon force-pushed the fix-service-container-definition branch 3 times, most recently from c028471 to df7ce28 Compare February 17, 2017 22:06
@hhamon
Copy link
Contributor Author

hhamon commented Feb 17, 2017

@nicolas-grekas can you review please.

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

@xabbuh xabbuh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@nicolas-grekas
Copy link
Member

Just wondering: should we also add these three aliases to the defaults also?

        <service id="Psr\Container\ContainerInterface" alias="service_container" public="false" />
        <service id="Symfony\Component\DependencyInjection\ContainerInterface" alias="service_container" public="false" />
        <service id="Symfony\Component\DependencyInjection\Container" alias="service_container" public="false" />

@nicolas-grekas nicolas-grekas added this to the 3.3 milestone Feb 18, 2017
@hhamon
Copy link
Contributor Author

hhamon commented Feb 18, 2017

What do you mean?

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Feb 18, 2017

I mean add three calls after the new one, to
setAlias(ContainerInterface::class/etc, new Alias('service_container', false))

@hhamon hhamon force-pushed the fix-service-container-definition branch 5 times, most recently from f59ab88 to 457ffde Compare February 19, 2017 15:56
@hhamon
Copy link
Contributor Author

hhamon commented Feb 19, 2017

I'm on it.

@hhamon
Copy link
Contributor Author

hhamon commented Feb 19, 2017

@nicolas-grekas better?

@nicolas-grekas
Copy link
Member

yes! you can also clean web.xml in FrameworkBundle and that will be good to me.

@hhamon
Copy link
Contributor Author

hhamon commented Feb 19, 2017

Shall we use autowire in web.xml? I can see only one reference to the service container that is injected into the ControllerResolver object.

@hhamon
Copy link
Contributor Author

hhamon commented Feb 19, 2017

I think you're talking about the services.xml file in FrameworkBundle to cleanup.

@hhamon
Copy link
Contributor Author

hhamon commented Feb 19, 2017

@nicolas-grekas done ;)

@nicolas-grekas
Copy link
Member

Missing test case fix:
https://travis-ci.org/symfony/symfony/jobs/203205123#L3297

@hhamon hhamon force-pushed the fix-service-container-definition branch 4 times, most recently from 8575394 to ba7e331 Compare February 21, 2017 09:50
@hhamon hhamon force-pushed the fix-service-container-definition branch 3 times, most recently from e61f4b8 to ffcd3c8 Compare February 21, 2017 21:41
@hhamon
Copy link
Contributor Author

hhamon commented Feb 22, 2017

Review from Symfony Core Team member is welcome.

@xabbuh
Copy link
Member

xabbuh commented Feb 22, 2017

👍 for the added aliases too

@@ -30,6 +30,11 @@ public function __construct()
$this->parameters = $this->getDefaultParameters();

$this->services = array();
$this->normalizedIds = array(
'psr\\container\\containerinterface' => 'Psr\\Container\\ContainerInterface',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicolas-grekas should we really dump normalized ids for services which got removed ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dunno :) do we really care? if someone wants to try fixing that, please do :) should be done while dumping - ie in PhpDumper I'd say.

@hhamon hhamon force-pushed the fix-service-container-definition branch from ffcd3c8 to 0d80817 Compare February 24, 2017 09:37
… definition of its related service container service (and aliases) in order to make compiler passes be able to reference the special service_container service.
@fabpot
Copy link
Member

fabpot commented Feb 28, 2017

Thank you @hhamon.

@fabpot fabpot merged commit 9c97496 into symfony:master Feb 28, 2017
fabpot added a commit that referenced this pull request Feb 28, 2017
…egister its own self referencing definition (hhamon)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[DependencyInjection] make the service container builder register its own self referencing definition

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | ~
| License       | MIT
| Doc PR        | ~

Commits
-------

9c97496 [DependencyInjection] make the service container builder register the definition of its related service container service (and aliases) in order to make compiler passes be able to reference the special service_container service.
nicolas-grekas added a commit that referenced this pull request May 22, 2017
This PR was merged into the 3.3 branch.

Discussion
----------

[DI] Remove dead service_container checks

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #... <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!--highly recommended for new features-->

Since #21627

Commits
-------

9a8ea93 [DI] Remove dead service_container checks
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.

6 participants