Skip to content

Commit 4b10abf

Browse files
committed
do not reference services in parameters
1 parent 7cbad6d commit 4b10abf

File tree

1 file changed

+0
-73
lines changed

1 file changed

+0
-73
lines changed

components/dependency_injection/parameters.rst

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -336,76 +336,3 @@ To disable this behavior, use the ``string`` type:
336336

337337
This is not available for YAML and PHP, because they already have built-in
338338
support for the PHP keywords.
339-
340-
Syntax for Referencing Services
341-
-------------------------------
342-
343-
You can of course also reference services, which looks a bit different in
344-
each format. You can configure the behavior if the referenced service does
345-
not exist. By default, an exception is thrown when a non-existent service
346-
is referenced.
347-
348-
YAML
349-
~~~~
350-
351-
Start the string with ``@`` or ``@?`` to reference a service in YAML.
352-
353-
* ``@mailer`` references the ``mailer`` service. If the service does not
354-
exist, an exception will be thrown;
355-
* ``@?mailer`` references the ``mailer`` service. If the service does not
356-
exist, it will be ignored;
357-
358-
.. code-block:: yaml
359-
360-
parameters:
361-
# if 'my_mailer' service isn't defined, an exception will be raised
362-
foo: @my_mailer
363-
364-
# if 'my_logger' service isn't defined, 'bar' will be null
365-
bar: @?my_logger
366-
367-
.. tip::
368-
369-
Use ``@@`` to escape the ``@`` symbol in YAML. ``@@mailer`` will be
370-
converted into the string ``"@mailer"`` instead of referencing the
371-
``mailer`` service.
372-
373-
XML
374-
~~~
375-
376-
In XML, use the ``service`` type. The behavior if the service does not exist
377-
can be specified using the ``on-invalid`` argument. By default, an exception
378-
is thrown. Valid values for ``on-invalid`` are ``null`` (uses ``null`` in place
379-
of the missing service) or ``ignored`` (very similar, except if used on a
380-
method call, the method call is removed).
381-
382-
.. code-block:: xml
383-
384-
<parameters>
385-
<!-- if 'my_mailer' service isn't defined, an exception will be raised -->
386-
<parameter key="foo" type="service" id="my_mailer" />
387-
388-
<!-- if 'my_logger' service isn't defined, 'bar' will be null -->
389-
<parameter key="bar" type="service" id="my_logger" on-invalid="null" />
390-
</parameters>
391-
392-
PHP
393-
~~~
394-
395-
In PHP, you can use the
396-
:class:`Symfony\\Component\\DependencyInjection\\Reference` class to reference
397-
a service. The invalid behavior is configured using the second constructor
398-
argument and constants from
399-
:class:`Symfony\\Component\\DependencyInjection\\ContainerInterface`.
400-
401-
.. code-block:: php
402-
403-
use Symfony\Component\DependencyInjection\Reference;
404-
405-
// if 'my_mailer' service isn't defined, an exception will be raised
406-
$container->setParameter('foo', new Reference('my_mailer'));
407-
408-
// if 'my_logger' service isn't defined, 'bar' will be null
409-
$container->setParameter('bar', new Reference('my_logger',
410-
ContainerInterface::NULL_ON_INVALID_REFERENCE
411-
));

0 commit comments

Comments
 (0)