diff --git a/service_container/alias_private.rst b/service_container/alias_private.rst index 537e279d5a9..d6fa3a163ef 100644 --- a/service_container/alias_private.rst +++ b/service_container/alias_private.rst @@ -149,7 +149,7 @@ Anonymous Services .. note:: - Anonymous services are only supported by the XML configuration format. + Anonymous services are only supported by the XML and YAML configuration formats. In some cases, you may want to prevent a service being used as a dependency of other services. This can be achieved by creating an anonymous service. These @@ -158,23 +158,74 @@ created where they are used. The following example shows how to inject an anonymous service into another service: -.. code-block:: xml +.. configuration-block:: + + .. code-block:: yaml + + # app/config/services.yml + services: + _defaults: + autowire: true + + AppBundle\Foo: + arguments: + - !service + class: AppBundle\AnonymousBar + autowire: true + + .. code-block:: xml + + + + + + + + + + + + + + + - - - +Using an anonymous service as a factory looks like this: - - - - - - - - +.. configuration-block:: + + .. code-block:: yaml + + # app/config/services.yml + services: + _defaults: + autowire: true + + AppBundle\Foo: + factory: [ !service { class: AppBundle\FooFactory }, 'constructFoo' ] + + .. code-block:: xml + + + + + + + + + + + + + + + Deprecating Services -------------------- @@ -186,8 +237,8 @@ or you decided not to maintain it anymore), you can deprecate its definition: .. code-block:: yaml - AppBundle\Service\OldService: - deprecated: The "%service_id%" service is deprecated since 2.8 and will be removed in 3.0. + AppBundle\Service\OldService: + deprecated: The "%service_id%" service is deprecated since 2.8 and will be removed in 3.0. .. code-block:: xml