From c0a7979055cabc715c142df13c5bc34d0af6a418 Mon Sep 17 00:00:00 2001 From: Robin Chalas Date: Tue, 19 Apr 2022 16:47:41 +0200 Subject: [PATCH] [DependencyInjection] Rename `#[InnerService]` to `#[MapDecorated]` --- .../Attribute/{InnerService.php => MapDecorated.php} | 2 +- src/Symfony/Component/DependencyInjection/CHANGELOG.md | 2 ++ .../DependencyInjection/Compiler/AutowirePass.php | 7 ++++--- .../Tests/Fixtures/includes/autowiring_classes_80.php | 8 ++++---- 4 files changed, 11 insertions(+), 8 deletions(-) rename src/Symfony/Component/DependencyInjection/Attribute/{InnerService.php => MapDecorated.php} (94%) diff --git a/src/Symfony/Component/DependencyInjection/Attribute/InnerService.php b/src/Symfony/Component/DependencyInjection/Attribute/MapDecorated.php similarity index 94% rename from src/Symfony/Component/DependencyInjection/Attribute/InnerService.php rename to src/Symfony/Component/DependencyInjection/Attribute/MapDecorated.php index 46e987e435183..4fbbf68c62492 100644 --- a/src/Symfony/Component/DependencyInjection/Attribute/InnerService.php +++ b/src/Symfony/Component/DependencyInjection/Attribute/MapDecorated.php @@ -12,6 +12,6 @@ namespace Symfony\Component\DependencyInjection\Attribute; #[\Attribute(\Attribute::TARGET_PARAMETER)] -class InnerService +class MapDecorated { } diff --git a/src/Symfony/Component/DependencyInjection/CHANGELOG.md b/src/Symfony/Component/DependencyInjection/CHANGELOG.md index 0bb0d6a7063db..ced60bd357c4c 100644 --- a/src/Symfony/Component/DependencyInjection/CHANGELOG.md +++ b/src/Symfony/Component/DependencyInjection/CHANGELOG.md @@ -4,6 +4,8 @@ CHANGELOG 6.1 --- + * Add `#[MapDecorated]` attribute telling to which parameter the decorated service should be mapped in a decorator + * Add `#[AsDecorator]` attribute to make a service decorates another * Add `$exclude` to `TaggedIterator` and `TaggedLocator` attributes * Add `$exclude` to `tagged_iterator` and `tagged_locator` configurator * Add an `env` function to the expression language provider diff --git a/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php b/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php index a47b6ba69be1f..b8634eafe4a41 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php @@ -15,7 +15,7 @@ use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument; use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument; use Symfony\Component\DependencyInjection\Attribute\Autowire; -use Symfony\Component\DependencyInjection\Attribute\InnerService; +use Symfony\Component\DependencyInjection\Attribute\MapDecorated; use Symfony\Component\DependencyInjection\Attribute\TaggedIterator; use Symfony\Component\DependencyInjection\Attribute\TaggedLocator; use Symfony\Component\DependencyInjection\Attribute\Target; @@ -273,8 +273,9 @@ private function autowireMethod(\ReflectionFunctionAbstract $reflectionMethod, a break; } - if (InnerService::class === $attribute->getName()) { - $arguments[$index] = new Reference($this->currentId.'.inner', ContainerInterface::NULL_ON_INVALID_REFERENCE); + if (MapDecorated::class === $attribute->getName()) { + $definition = $this->container->getDefinition($this->currentId); + $arguments[$index] = new Reference($definition->innerServiceId ?? $this->currentId.'.inner', $definition->decorationOnInvalid ?? ContainerInterface::NULL_ON_INVALID_REFERENCE); break; } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/autowiring_classes_80.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/autowiring_classes_80.php index de2583d3b2ed3..c1c772b684a48 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/autowiring_classes_80.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/autowiring_classes_80.php @@ -4,7 +4,7 @@ use Symfony\Component\DependencyInjection\Attribute\AsDecorator; use Symfony\Component\DependencyInjection\Attribute\Autowire; -use Symfony\Component\DependencyInjection\Attribute\InnerService; +use Symfony\Component\DependencyInjection\Attribute\MapDecorated; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Contracts\Service\Attribute\Required; @@ -65,7 +65,7 @@ class AsDecoratorFoo implements AsDecoratorInterface #[AsDecorator(decorates: AsDecoratorFoo::class, priority: 10)] class AsDecoratorBar10 implements AsDecoratorInterface { - public function __construct(string $arg1, #[InnerService] AsDecoratorInterface $inner) + public function __construct(string $arg1, #[MapDecorated] AsDecoratorInterface $inner) { } } @@ -73,7 +73,7 @@ public function __construct(string $arg1, #[InnerService] AsDecoratorInterface $ #[AsDecorator(decorates: AsDecoratorFoo::class, priority: 20)] class AsDecoratorBar20 implements AsDecoratorInterface { - public function __construct(string $arg1, #[InnerService] AsDecoratorInterface $inner) + public function __construct(string $arg1, #[MapDecorated] AsDecoratorInterface $inner) { } } @@ -81,7 +81,7 @@ public function __construct(string $arg1, #[InnerService] AsDecoratorInterface $ #[AsDecorator(decorates: \NonExistent::class, onInvalid: ContainerInterface::NULL_ON_INVALID_REFERENCE)] class AsDecoratorBaz implements AsDecoratorInterface { - public function __construct(#[InnerService] AsDecoratorInterface $inner = null) + public function __construct(#[MapDecorated] AsDecoratorInterface $inner = null) { } }