@@ -382,38 +382,31 @@ Three different behaviors are available:
382
382
* ``null ``: When used, the container will keep the decorator
383
383
service and will set the decorated one to `null `.
384
384
385
- .. note ::
386
-
387
- If you are using yaml to describe your services, please ensure that
388
- ``null `` value is wrapped with quotes. In fact in yaml, ``null `` will be interpreted
389
- as the null value and not as the null string. Therefore, the compiler will throw
390
- an ``InvalidArgumentException ``
391
-
392
- .. code-block :: yaml
393
-
394
- Foo :
395
- decorates : Foo
396
- decoration_on_invalid : ' null'
397
- arguments : ['@Bar.inner']
398
-
399
385
.. tip ::
400
386
401
387
When using ``null ``, you may update the decorator's constructor in
402
388
order to make decorated dependency nullable. In this way, you will be able to
403
389
check the presence of decorated service in other methods.
404
390
391
+ .. code-block :: yaml
392
+
393
+ App\Service\DecoratorService :
394
+ decorates : Acme\OptionalBundle\Service\OptionalService
395
+ decoration_on_invalid : null
396
+ arguments : ['@App\Service\DecoratorService.inner']
397
+
405
398
::
406
399
407
400
namespace App\Service;
408
401
409
- use App\ Service\OptionalDecoratedService ;
402
+ use Acme\OptionalBundle\ Service\OptionalService ;
410
403
411
404
class DecoratorService
412
405
{
413
406
private $decorated;
414
407
415
- - public function __construct(OptionalDecoratedService $decorated)
416
- + public function __construct(?OptionalDecoratedService $decorated)
408
+ - public function __construct(OptionalService $decorated)
409
+ + public function __construct(?OptionalService $decorated)
417
410
{
418
411
$this->decorated = $decorated;
419
412
}
0 commit comments