@@ -313,12 +313,12 @@ The generated code will be the following::
313
313
314
314
$this->services[Foo::class] = new Baz(new Bar(new Foo()));
315
315
316
- Control the behavior when the decorated service does not exist
316
+ Control the Behavior When the Decorated Service Does Not Exist
317
317
--------------------------------------------------------------
318
318
319
- Let's imagine you have a decorator that decorates a service defined in another bundle.
319
+ Let's imagine you have a decorator that decorates a service defined by another bundle.
320
320
If for some reasons, that bundle is missing, the ``decoration_on_invalid ``
321
- option will allow you to handle the lack of decorated service.
321
+ option will allow you to handle the lack of the decorated service.
322
322
323
323
.. configuration-block ::
324
324
@@ -375,18 +375,18 @@ option will allow you to handle the lack of decorated service.
375
375
376
376
Three different behaviors are available:
377
377
378
- * ``exception ``: The default behavior. When used, a ``ServiceNotFoundException ``
379
- will be thrown telling that decorator's dependency is missing.
378
+ * ``exception ``: When used, a ``ServiceNotFoundException ``
379
+ will be thrown telling that decorator's dependency is missing. (default)
380
380
* ``ignore ``: Using that behavior, the container will remove either decorator
381
381
and decorated services.
382
382
* ``null ``: When used, the container will keep the decorator
383
- service and will set the decorated one to `null `.
383
+ service and will set the decorated one to `` null ` `.
384
384
385
385
.. tip ::
386
386
387
387
When using ``null ``, you may update the decorator's constructor in
388
388
order to make decorated dependency nullable. In this way, you will be able to
389
- check the presence of decorated service in other methods.
389
+ check the presence of the decorated service in other methods.
390
390
391
391
.. code-block :: yaml
392
392
@@ -395,7 +395,7 @@ Three different behaviors are available:
395
395
decoration_on_invalid : null
396
396
arguments : ['@App\Service\DecoratorService.inner']
397
397
398
- ::
398
+ .. code-block: php
399
399
400
400
namespace App\Service;
401
401
@@ -405,17 +405,16 @@ Three different behaviors are available:
405
405
{
406
406
private $decorated;
407
407
408
- - public function __construct(OptionalService $decorated)
409
- + public function __construct(?OptionalService $decorated)
408
+ public function __construct(?OptionalService $decorated)
410
409
{
411
410
$this->decorated = $decorated;
412
411
}
413
412
414
413
public function tellInterestingStuff(): string
415
414
{
416
- + if (!$this->decorated) {
417
- + return 'Just one interesting thing';
418
- + }
415
+ if (!$this->decorated) {
416
+ return 'Just one interesting thing';
417
+ }
419
418
420
419
return $this->decorated->tellInterestingStuff().' + one more interesting thing';
421
420
}
@@ -426,6 +425,6 @@ Three different behaviors are available:
426
425
Sometimes, you may want to add a compiler pass that creates service
427
426
definitions on the fly. If you want to decorate such a service,
428
427
be sure that your compiler pass is registered with ``PassConfig::TYPE_BEFORE_OPTIMIZATION ``
429
- type so that the decoration pass will be able to find created services.
428
+ type so that the decoration pass will be able to find the created services.
430
429
431
430
.. _`Decorator pattern` : https://en.wikipedia.org/wiki/Decorator_pattern
0 commit comments