Skip to content

Commit

Permalink
Tried to clarify private services
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterj committed Dec 28, 2014
1 parent a51c623 commit d89ad21
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions components/dependency_injection/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ argument for another service.

.. _inlined-private-services:

.. note::
Since a container is not able to detect if a service is retrieved from inside
the container or the outside, a private service may still be retrieved using
the ``get()`` method.

If you use a private service as an argument to only one other service,
this will result in an inlined instantiation (e.g. ``new PrivateFooBar()``)
inside this other service, making it publicly unavailable at runtime.
What makes private services special, is that they are converted from services
to inlined instantiation (e.g. ``new PrivateThing()``) when they are only
injected once, to increase the container performance. This means that you can
never be sure if a private service exists in the container.

Simply said: A service will be private when you do not want to access it
directly from your code.
Expand Down Expand Up @@ -60,7 +63,8 @@ Here is an example:
$definition->setPublic(false);
$container->setDefinition('foo', $definition);
Now that the service is private, you *cannot* call::
Now that the service is private, you *should not* call (should not means, this
*might* fail, see the explaination above)::

$container->get('foo');

Expand Down

0 comments on commit d89ad21

Please sign in to comment.