Permalink
Browse files

minor #3641 Added some examples to the "services as parameters" secti…

…on (javiereguiluz)

This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes #3641).

Discussion
----------

Added some examples to the "services as parameters" section

| Q             | A
| ------------- | ---
| Doc fix?      | no
| New docs?     | yes
| Applies to    | 2.3+
| Fixed tickets | no

Commits
-------

745f3a6 Removed the file path comments because this doc is for the component and it should not make any reference to Symfony
6abb310 Added some examples to the "services as parameters" section
  • Loading branch information...
weaverryan committed Mar 19, 2014
2 parents 12a6676 + c0d766e commit 93c35d01a5d8dac8aa4ac672f367b5679bef72a5
Showing with 31 additions and 0 deletions.
  1. +31 −0 components/dependency_injection/parameters.rst
@@ -343,6 +343,15 @@ 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
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 +367,16 @@ 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
<parameters>
<!-- if 'my_mailer' service isn't defined, an exception will be raised -->
<parameter key="foo" type="service" id="my_mailer" />
<!-- if 'my_logger' service isn't defined, 'bar' will be null -->
<parameter key="bar" type="service" id="my_logger" on-invalid="null" />
</parameters>
PHP
~~~
@@ -366,3 +385,15 @@ 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
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
));

0 comments on commit 93c35d0

Please sign in to comment.