From 4b10abfacf4cb4d3fe1f601862eedd9eaec615f7 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sat, 13 Sep 2014 10:00:11 +0200 Subject: [PATCH] do not reference services in parameters --- .../dependency_injection/parameters.rst | 73 ------------------- 1 file changed, 73 deletions(-) diff --git a/components/dependency_injection/parameters.rst b/components/dependency_injection/parameters.rst index 86cf5a489eb..9b47e5141b9 100644 --- a/components/dependency_injection/parameters.rst +++ b/components/dependency_injection/parameters.rst @@ -336,76 +336,3 @@ To disable this behavior, use the ``string`` type: This is not available for YAML and PHP, because they already have built-in support for the PHP keywords. - -Syntax for Referencing Services -------------------------------- - -You can of course also reference services, which looks a bit different in -each format. You can configure the behavior if the referenced service does -not exist. By default, an exception is thrown when a non-existent service -is referenced. - -YAML -~~~~ - -Start the string with ``@`` or ``@?`` to reference a service in YAML. - -* ``@mailer`` references the ``mailer`` service. If the service does not - exist, an exception will be thrown; -* ``@?mailer`` references the ``mailer`` service. If the service does not - exist, it will be ignored; - -.. code-block:: yaml - - parameters: - # if 'my_mailer' service isn't defined, an exception will be raised - foo: @my_mailer - - # if 'my_logger' service isn't defined, 'bar' will be null - bar: @?my_logger - -.. tip:: - - Use ``@@`` to escape the ``@`` symbol in YAML. ``@@mailer`` will be - converted into the string ``"@mailer"`` instead of referencing the - ``mailer`` service. - -XML -~~~ - -In XML, use the ``service`` type. The behavior if the service does not exist -can be specified using the ``on-invalid`` argument. By default, an exception -is thrown. Valid values for ``on-invalid`` are ``null`` (uses ``null`` in place -of the missing service) or ``ignored`` (very similar, except if used on a -method call, the method call is removed). - -.. code-block:: xml - - - - - - - - - -PHP -~~~ - -In PHP, you can use the -:class:`Symfony\\Component\\DependencyInjection\\Reference` class to reference -a service. The invalid behavior is configured using the second constructor -argument and constants from -:class:`Symfony\\Component\\DependencyInjection\\ContainerInterface`. - -.. code-block:: php - - use Symfony\Component\DependencyInjection\Reference; - - // if 'my_mailer' service isn't defined, an exception will be raised - $container->setParameter('foo', new Reference('my_mailer')); - - // if 'my_logger' service isn't defined, 'bar' will be null - $container->setParameter('bar', new Reference('my_logger', - ContainerInterface::NULL_ON_INVALID_REFERENCE - ));