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