-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection] Private services are not always private in dumped container #19117
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
Labels
Comments
see #15703 |
Thanks @xabbuh ! |
So, shouldn't we deprecated this behavior and make private services really private? |
Indeed. Making them "really" private is just a matter of changing their id by a random one. Should be easy enough to implement. |
I'll fix it then ;) |
hhamon
pushed a commit
to hhamon/symfony
that referenced
this issue
Jun 22, 2016
hhamon
pushed a commit
to hhamon/symfony
that referenced
this issue
Jun 22, 2016
hhamon
pushed a commit
to hhamon/symfony
that referenced
this issue
Jun 22, 2016
hhamon
pushed a commit
to hhamon/symfony
that referenced
this issue
Jun 22, 2016
hhamon
pushed a commit
to hhamon/symfony
that referenced
this issue
Jun 22, 2016
hhamon
pushed a commit
to hhamon/symfony
that referenced
this issue
Jun 23, 2016
hhamon
pushed a commit
to hhamon/symfony
that referenced
this issue
Jun 23, 2016
hhamon
pushed a commit
to hhamon/symfony
that referenced
this issue
Jun 23, 2016
hhamon
pushed a commit
to hhamon/symfony
that referenced
this issue
Jun 27, 2016
hhamon
pushed a commit
to hhamon/symfony
that referenced
this issue
Jun 27, 2016
hhamon
pushed a commit
to hhamon/symfony
that referenced
this issue
Jun 27, 2016
hhamon
pushed a commit
to hhamon/symfony
that referenced
this issue
Jun 28, 2016
fabpot
added a commit
that referenced
this issue
Jun 29, 2016
…ed services. (hhamon) This PR was merged into the 3.2-dev branch. Discussion ---------- [DependencyInjection] deprecate access to private shared services. | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | #19117 | License | MIT | Doc PR | ~ Commits ------- 4ed70c4 [DependencyInjection] deprecate access to private shared services. Fixes issue #19117.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
While delivering a training on Symfony 3.1 last week, my students and I stumbled upon an unexpected behavior. Some private services we defined were public in the end in the final dumped container. It was possible to request them outside of the container thanks to its
get()
method.Consider the following scenarii.
Use Case 1: Orphan Private Service is Removed
This use case works as expected. An orphan private service is always removed from the final dumped container. It can never be requested to the container.
Use Case 2 : Private Service Referenced Once is Inlined
This use case also works as expected. The private
app.foo
service is inlined in the generatedgetApp_BarService()
method in the compiled container. Theapp.foo
service cannot be requested outside of the container because it's inlined.Use Case 3 : Private Service Referenced More Than Once is Shared and Public
This is the problem! Consider the following definition.
In this situation, the private service
app.foo
is referenced twice by two public services. As such the compiled container generates a protectedgetApp_FooService()
method that will create theapp.foo
service on demand when its requested with theContainer::get()
method. Theapp.foo
service reference will be stored in the$services
array of the dumped container.It's also possible to request this service outside of the container:
The final dumped container looks like the following in my Symfony 3.1 SE project:
The text was updated successfully, but these errors were encountered: