Skip to content

[DI] configure inlined services before injecting when dumping the container #28385

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
wants to merge 1 commit into from

Conversation

nicolas-grekas
Copy link
Member

Q A
Branch? 3.4 (WIP on 4.1 for now)
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #28304
License MIT
Doc PR -

#28060 introduced a change in the way inline services are dumped: these instances could end up being configured after being injected. This breaks e.g. using Doctrine's Configuration instances, which are expected to be fully defined before being injected into their consumers.

Fixing this required a significant refactorization because I was just unable to reason with the heavily scrambled logic in place right now. The new logic is still non-trivial, but at least it's manageable, thus easier to get correct.

(I'll see if I can figure out a way to remove the whitespace differences also.)

To be retargeted at 3.4 once validated.

$b->p2 = $c;

return $instance;
return $this->services['foo'] = new \c1($a, $b);
Copy link
Member Author

Choose a reason for hiding this comment

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

The effect of the fix is visible here: $b is now fully configured when it is injected, where previously its p2 property was set after the injection.

@@ -620,7 +509,7 @@ private function addServiceMethodCalls(Definition $definition, string $variableN
return $calls;
}

private function addServiceProperties(Definition $definition, $variableName = 'instance')
private function addServiceProperties(Definition $definition, string $variableName = 'instance')
Copy link
Member

Choose a reason for hiding this comment

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

you should not add scalar typehints if you want to retarget it to 3.4

}
}

return $hasSelfRef;
Copy link
Member

Choose a reason for hiding this comment

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

this does not return a boolean

@stof
Copy link
Member

stof commented Sep 7, 2018

it would also be great to add a test reproducing the use case of Doctrine, to ensure that such instantiation works (and I mean a functional test actually using the compiled container to instantiate the service, not a test only asserting the output of the dumper)

@nicolas-grekas
Copy link
Member Author

Replaced by #28388 on 3.4 (ready).

@nicolas-grekas nicolas-grekas deleted the di-fix branch September 7, 2018 11:46
nicolas-grekas added a commit that referenced this pull request Sep 8, 2018
… dumping the container (nicolas-grekas)

This PR was merged into the 3.4 branch.

Discussion
----------

[DI] configure inlined services before injecting them when dumping the container

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

#28060 introduced a change in the way inline services are dumped: these instances could end up being configured *after* being injected. This breaks e.g. using Doctrine's Configuration instances, which are expected to be fully defined before being injected into their consumers.

Fixing this required a significant refactorization because I was just unable to reason with the heavily scrambled logic in place right now. The new logic is still non-trivial, but at least it's manageable, thus easier to get correct.

(Replaces #28385 which is the same applied to 4.1 - should help with merges.)

Commits
-------

e5c5405 [DI] configure inlined services before injecting them when dumping the container
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.

3 participants