@@ -320,8 +320,8 @@ To fix that, add an :ref:`alias <service-autowiring-alias>`:
320320
321321App\Util\Rot13Transformer :~
322322
323- # the`` App\Util\Rot13Transformer`` service will be injected when
324- # an`` App\Util\TransformerInterface`` type-hint is detected
323+ # the App\Util\Rot13Transformer service will be injected when
324+ # an App\Util\TransformerInterface type-hint is detected
325325App\Util\TransformerInterface :' @App\Util\Rot13Transformer'
326326
327327 ..code-block ::xml
@@ -428,7 +428,7 @@ type hinted, but use the ``UppercaseTransformer`` implementation in some
428428specific cases. To do so, you can create a normal alias from the
429429``TransformerInterface `` interface to ``Rot13Transformer ``, and then
430430create a *named autowiring alias * from a special string containing the
431- interface followed bya variable name matching the one you use when doing
431+ interface followed byan argument name matching the one you use when doing
432432the injection::
433433
434434 // src/Service/MastodonClient.php
@@ -464,13 +464,13 @@ the injection::
464464App\Util\Rot13Transformer :~
465465App\Util\UppercaseTransformer :~
466466
467- # the`` App\Util\UppercaseTransformer`` service will be
468- # injected when an`` App\Util\TransformerInterface``
469- # type-hint for a`` $shoutyTransformer`` argument is detected.
467+ # the App\Util\UppercaseTransformer service will be
468+ # injected when an App\Util\TransformerInterface
469+ # type-hint for a $shoutyTransformer argument is detected
470470App\Util\TransformerInterface $shoutyTransformer :' @App\Util\UppercaseTransformer'
471471
472472# If the argument used for injection does not match, but the
473- # type-hint still matches, the`` App\Util\Rot13Transformer``
473+ # type-hint still matches, the App\Util\Rot13Transformer
474474# service will be injected.
475475App\Util\TransformerInterface :' @App\Util\Rot13Transformer'
476476
@@ -527,7 +527,7 @@ the injection::
527527
528528 // the App\Util\UppercaseTransformer service will be
529529 // injected when an App\Util\TransformerInterface
530- // type-hint for a $shoutyTransformer argument is detected.
530+ // type-hint for a $shoutyTransformer argument is detected
531531 $services->alias(TransformerInterface::class.' $shoutyTransformer', UppercaseTransformer::class);
532532
533533 // If the argument used for injection does not match, but the
@@ -555,13 +555,17 @@ under the arguments key.
555555
556556Another possibility is to use the ``#[Target] `` attribute. By using this attribute
557557on the argument you want to autowire, you can define exactly which service to inject
558- byusing its alias. Thanks to this, you're able to have multiple services implementing
559- the same interface and keep the argument name decorrelated of any implementation name
560- (like shown in the example above).
558+ bypassing the name of the argument used in the named alias. Thanks to this, you're able
559+ to have multiple services implementing the same interface and keep the argument name
560+ decorrelated of any implementation name (like shown in the example above).
561561
562- Let's say you defined the ``app.uppercase_transformer `` alias for the
563- ``App\Util\UppercaseTransformer `` service. You would be able to use the ``#[Target] ``
564- attribute like this::
562+ ..warning ::
563+
564+ The ``#[Target] `` attribute only accepts the name of the argument used in the named
565+ alias, it **does not ** accept service ids or service aliases.
566+
567+ Suppose you want to inject the ``App\Util\UppercaseTransformer `` service. You would use
568+ the ``#[Target] `` attribute by passing the name of the ``$shoutyTransformer `` argument::
565569
566570 // src/Service/MastodonClient.php
567571 namespace App\Service;
@@ -573,12 +577,16 @@ attribute like this::
573577 {
574578 private $transformer;
575579
576- public function __construct(#[Target('app.uppercase_transformer')] TransformerInterface $transformer)
577- {
580+ public function __construct(
581+ #[Target('shoutyTransformer')] TransformerInterface $transformer,
582+ ) {
578583 $this->transformer = $transformer;
579584 }
580585 }
581586
587+ Since the ``#[Target] `` attribute normalizes the string passed to it to its camelCased form,
588+ name variations such as ``shouty.transformer `` also work.
589+
582590..note ::
583591
584592 Some IDEs will show an error when using ``#[Target] `` as in the previous example: