Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit deb369d

Browse filesBrowse files
committed
minor #9909 Add section about anonymous services (Tim Goudriaan)
This PR was merged into the 2.8 branch. Discussion ---------- Add section about anonymous services Attempts to fix #5854 for Symfony 2.8 Commits ------- f777445 Add section about anonymous services
2 parents 1a62f56 + f777445 commit deb369d
Copy full SHA for deb369d

File tree

1 file changed

+36
-0
lines changed
Filter options

1 file changed

+36
-0
lines changed

‎service_container/alias_private.rst

Copy file name to clipboardExpand all lines: service_container/alias_private.rst
+36Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,42 @@ This means that when using the container directly, you can access the
129129
# ...
130130
app.mailer: '@app.phpmailer'
131131
132+
Anonymous Services
133+
--------------------
134+
135+
.. note::
136+
137+
Anonymous services are currently only supported by the XML configuration format.
138+
139+
In some cases, you may want to limit access to a service outside of its
140+
intended scope. This is useful when you want to prevent other services from
141+
using the service as their own dependency. This can be achieved by creating an
142+
*anonymous service*.
143+
144+
For Symfony, an anonymous service is nothing more than a service without a
145+
identifying name which is defined directly in its use context. The following
146+
example shows how an anonymous service can be injected into another service:
147+
148+
.. configuration-block::
149+
150+
.. code-block:: xml
151+
152+
<!-- app/config/services.xml -->
153+
<?xml version="1.0" encoding="UTF-8" ?>
154+
<container xmlns="http://symfony.com/schema/dic/services"
155+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
156+
xsi:schemaLocation="http://symfony.com/schema/dic/services
157+
http://symfony.com/schema/dic/services/services-1.0.xsd">
158+
159+
<services>
160+
<service id="foo" class="AppBundle\Foo">
161+
<argument type="service">
162+
<service class="AppBundle\AnonymousBar" />
163+
</argument>
164+
</service>
165+
</services>
166+
</container>
167+
132168
Deprecating Services
133169
--------------------
134170

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.