Skip to content

Commit 601f0bc

Browse files
committed
Applying reviews
1 parent db00c9a commit 601f0bc

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

service_container/service_decoration.rst

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -313,12 +313,12 @@ The generated code will be the following::
313313

314314
$this->services[Foo::class] = new Baz(new Bar(new Foo()));
315315

316-
Control the behavior when the decorated service does not exist
316+
Control the Behavior When the Decorated Service Does Not Exist
317317
--------------------------------------------------------------
318318

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.
320320
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.
322322

323323
.. configuration-block::
324324

@@ -375,18 +375,18 @@ option will allow you to handle the lack of decorated service.
375375
376376
Three different behaviors are available:
377377

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)
380380
* ``ignore``: Using that behavior, the container will remove either decorator
381381
and decorated services.
382382
* ``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``.
384384

385385
.. tip::
386386

387387
When using ``null``, you may update the decorator's constructor in
388388
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.
390390

391391
.. code-block:: yaml
392392
@@ -395,7 +395,7 @@ Three different behaviors are available:
395395
decoration_on_invalid: null
396396
arguments: ['@App\Service\DecoratorService.inner']
397397
398-
::
398+
.. code-block: php
399399
400400
namespace App\Service;
401401
@@ -405,17 +405,16 @@ Three different behaviors are available:
405405
{
406406
private $decorated;
407407
408-
- public function __construct(OptionalService $decorated)
409-
+ public function __construct(?OptionalService $decorated)
408+
public function __construct(?OptionalService $decorated)
410409
{
411410
$this->decorated = $decorated;
412411
}
413412
414413
public function tellInterestingStuff(): string
415414
{
416-
+ if (!$this->decorated) {
417-
+ return 'Just one interesting thing';
418-
+ }
415+
if (!$this->decorated) {
416+
return 'Just one interesting thing';
417+
}
419418
420419
return $this->decorated->tellInterestingStuff().' + one more interesting thing';
421420
}
@@ -426,6 +425,6 @@ Three different behaviors are available:
426425
Sometimes, you may want to add a compiler pass that creates service
427426
definitions on the fly. If you want to decorate such a service,
428427
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.
430429

431430
.. _`Decorator pattern`: https://en.wikipedia.org/wiki/Decorator_pattern

0 commit comments

Comments
 (0)