Skip to content
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

Tried to clarify private services #4656

Merged
merged 1 commit into from
Jan 3, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

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

Would it be OK to mention that Symfony does this for performance reasons?

Copy link
Contributor

Choose a reason for hiding this comment

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

i think we have to mention that it is JUST for performance reason.

Copy link
Member Author

Choose a reason for hiding this comment

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

added it

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