@@ -343,6 +343,16 @@ Start the string with ``@`` or ``@?`` to reference a service in YAML.
343
343
* ``@?mailer `` references the ``mailer `` service. If the service does not
344
344
exist, it will be ignored;
345
345
346
+ .. code-block :: yaml
347
+
348
+ # app/config/config.yml
349
+ parameters :
350
+ # if 'my_mailer' service isn't defined, an exception will be raised
351
+ foo : @my_mailer
352
+
353
+ # if 'my_logger' service isn't defined, 'bar' will be null
354
+ bar : @?my_logger
355
+
346
356
.. tip ::
347
357
348
358
Use ``@@ `` to escape the ``@ `` symbol in YAML. ``@@mailer `` will be
8000
@@ -358,6 +368,17 @@ is thrown. Valid values for ``on-invalid`` are ``null`` (uses ``null`` in place
358
368
of the missing service) or ``ignored `` (very similar, except if used on a
359
369
method call, the method call is removed).
360
370
371
+ .. code-block :: xml
372
+
373
+ <!-- app/config/config.xml -->
374
+ <parameters >
375
+ <!-- if 'my_mailer' service isn't defined, an exception will be raised -->
376
+ <parameter key =" foo" type =" service" id =" my_mailer" />
377
+
378
+ <!-- if 'my_logger' service isn't defined, 'bar' will be null -->
379
+ <parameter key =" bar" type =" service" id =" my_logger" on-invalid =" null" />
380
+ </parameters >
381
+
361
382
PHP
362
383
~~~
363
384
@@ -366,3 +387,16 @@ In PHP, you can use the
366
387
a service. The invalid behavior is configured using the second constructor
367
388
argument and constants from
368
389
:class: `Symfony\\ Component\\ DependencyInjection\\ ContainerInterface `.
390
+
391
+ .. code-block :: php
392
+
393
+ // app/config/config.php
394
+ use Symfony\Component\DependencyInjection\Reference;
395
+
396
+ // if 'my_mailer' service isn't defined, an exception will be raised
397
+ $container->setParameter('foo', new Reference('my_mailer'));
398
+
399
+ // if 'my_logger' service isn't defined, 'bar' will be null
400
+ $container->setParameter('bar', new Reference('my_logger',
401
+ ContainerInterface::NULL_ON_INVALID_REFERENCE
402
+ ));
0 commit comments