From 6abb310afc95646806e0da1ad96d662ed61280e8 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Thu, 6 Mar 2014 12:11:26 +0100 Subject: [PATCH 1/2] Added some examples to the "services as parameters" section --- .../dependency_injection/parameters.rst | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/components/dependency_injection/parameters.rst b/components/dependency_injection/parameters.rst index 98194076885..702ecb82a98 100644 --- a/components/dependency_injection/parameters.rst +++ b/components/dependency_injection/parameters.rst @@ -344,6 +344,16 @@ Start the string with ``@`` or ``@?`` to reference a service in YAML. * ``@?mailer`` references the ``mailer`` service. If the service does not exist, it will be ignored; +.. code-block:: yaml + + # app/config/config.yml + 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 @@ -359,6 +369,17 @@ 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 ~~~ @@ -367,3 +388,16 @@ In PHP, you can use the a service. The invalid behavior is configured using the second constructor argument and constants from :class:`Symfony\\Component\\DependencyInjection\\ContainerInterface`. + +.. code-block:: php + + // app/config/config.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 + )); From 745f3a664e9a4b70c8680e99cad8b3ce12963385 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Sat, 8 Mar 2014 12:11:27 +0100 Subject: [PATCH 2/2] Removed the file path comments because this doc is for the component and it should not make any reference to Symfony --- components/dependency_injection/parameters.rst | 3 --- 1 file changed, 3 deletions(-) diff --git a/components/dependency_injection/parameters.rst b/components/dependency_injection/parameters.rst index 702ecb82a98..aca1b1f8715 100644 --- a/components/dependency_injection/parameters.rst +++ b/components/dependency_injection/parameters.rst @@ -346,7 +346,6 @@ Start the string with ``@`` or ``@?`` to reference a service in YAML. .. code-block:: yaml - # app/config/config.yml parameters: # if 'my_mailer' service isn't defined, an exception will be raised foo: @my_mailer @@ -371,7 +370,6 @@ method call, the method call is removed). .. code-block:: xml - @@ -391,7 +389,6 @@ argument and constants from .. code-block:: php - // app/config/config.php use Symfony\Component\DependencyInjection\Reference; // if 'my_mailer' service isn't defined, an exception will be raised