From fabdd8ab2cb652aa56a8e213c8dce27ab115b040 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 24edfc4ff98..b4209e7f68a 100644 --- a/components/dependency_injection/parameters.rst +++ b/components/dependency_injection/parameters.rst @@ -343,6 +343,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 @@ -358,6 +368,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 ~~~ @@ -366,3 +387,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 c0d766eeef5a15c92ceca4448d3f861c0dd5716c 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 b4209e7f68a..e30a186fb76 100644 --- a/components/dependency_injection/parameters.rst +++ b/components/dependency_injection/parameters.rst @@ -345,7 +345,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 @@ -370,7 +369,6 @@ method call, the method call is removed). .. code-block:: xml - @@ -390,7 +388,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