8000 feature #46112 [DependencyInjection] Rename `#[InnerService]` to `#[M… · symfony/symfony@2add2f2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2add2f2

Browse files
committed
feature #46112 [DependencyInjection] Rename #[InnerService] to #[MapDecorated] (chalasr)
This PR was merged into the 6.1 branch. Discussion ---------- [DependencyInjection] Rename `#[InnerService]` to `#[MapDecorated]` | Q | A | ------------- | --- | Branch? | 6.1 | Bug fix? | no | New feature? | no but tweaks one #45834 | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - When talking about the decorator pattern outside of Symfony, the term `inner` is pretty much (if not totally) inexistent. Worse, it makes the concept harder to explain. Take "there is a decorator and a decorated object" vs "there is a decorator and an inner object": using the later form, one has to explain both what is the decorator and what is the inner. While using the former, explaining what the decorator makes it obvious what the decorated is. I propose to take the addition of this attribute as an opportunity to start making this special term go away. Also I removed the `Service` suffix. It is tempting to keep it for explicitness, but it feels kinda redundant and AFAIK no other core attribute has such redundant suffix, maybe because their namespace is enough to indicate their target. Commits ------- c0a7979 [DependencyInjection] Rename `#[InnerService]` to `#[MapDecorated]`
2 parents 45ca083 + c0a7979 commit 2add2f2

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

src/Symfony/Component/DependencyInjection/Attribute/InnerService.php renamed to src/Symfony/Component/DependencyInjection/Attribute/MapDecorated.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
namespace Symfony\Component\DependencyInjection\Attribute;
1313

1414
#[\Attribute(\Attribute::TARGET_PARAMETER)]
15-
class InnerService
15+
class MapDecorated
1616
{
1717
}

src/Symfony/Component/DependencyInjection/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ CHANGELOG
44
6.1
55
---
66

7+
* Add `#[MapDecorated]` attribute telling to which parameter the decorated service should be mapped in a decorator
8+
* Add `#[AsDecorator]` attribute to make a service decorates another
79
* Add `$exclude` to `TaggedIterator` and `TaggedLocator` attributes
810
* Add `$exclude` to `tagged_iterator` and `tagged_locator` configurator
911
* Add an `env` function to the expression language provider

src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
1616
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
1717
use Symfony\Component\DependencyInjection\Attribute\Autowire;
18-
use Symfony\Component\DependencyInjection\Attribute\InnerService;
18+
use Symfony\Component\DependencyInjection\Attribute\MapDecorated;
1919
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
8000
2020
use Symfony\Component\DependencyInjection\Attribute\TaggedLocator;
2121
use Symfony\Component\DependencyInjection\Attribute\Target;
@@ -273,8 +273,9 @@ private function autowireMethod(\ReflectionFunctionAbstract $reflectionMethod, a
273273
break;
274274
}
275275

276-
if (InnerService::class === $attribute->getName()) {
277-
$arguments[$index] = new Reference($this->currentId.'.inner', ContainerInterface::NULL_ON_INVALID_REFERENCE);
276+
if (MapDecorated::class === $attribute->getName()) {
277+
$definition = $this->container->getDefinition($this->currentId);
278+
$arguments[$index] = new Reference($definition->innerServiceId ?? $this->currentId.'.inner', $definition->decorationOnInvalid ?? ContainerInterface::NULL_ON_INVALID_REFERENCE);
278279

279280
break;
280281
}

src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/autowiring_classes_80.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Symfony\Component\DependencyInjection\Attribute\AsDecorator;
66
use Symfony\Component\DependencyInjection\Attribute\Autowire;
7-
use Symfony\Component\DependencyInjection\Attribute\InnerService;
7+
use Symfony\Component\DependencyInjection\Attribute\MapDecorated;
88
use Symfony\Component\DependencyInjection\ContainerInterface;
99
use Symfony\Contracts\Service\Attribute\Required;
1010

@@ -65,23 +65,23 @@ class AsDecoratorFoo implements AsDecoratorInterface
6565
#[AsDecorator(decorates: AsDecoratorFoo::class, priority: 10)]
6666
class AsDecoratorBar10 implements AsDecoratorInterface
6767
{
68-
public function __construct(string $arg1, #[InnerService] AsDecoratorInterface $inner)
68+
public function __construct(string $arg1, #[MapDecorated] AsDecoratorInterface $inner)
6969
{
7070
}
7171
}
7272

7373
#[AsDecorator(decorates: AsDecoratorFoo::class, priority: 20)]
7474
class AsDecoratorBar20 implements AsDecoratorInterface
7575
{
76-
public function __construct(string $arg1, #[InnerService] AsDecoratorInterface $inner)
76+
public function __construct(string $arg1, #[MapDecorated] AsDecoratorInterface $inner)
7777
{
7878
}
7979
}
8080

8181
#[AsDecorator(decorates: \NonExistent::class, onInvalid: ContainerInterface::NULL_ON_INVALID_REFERENCE)]
8282
class AsDecoratorBaz implements AsDecoratorInterface
8383
{
84-
public function __construct(#[InnerService] AsDecoratorInterface $inner = null)
84+
public function __construct(#[MapDecorated] AsDecoratorInterface $inner = null)
8585
{
8686
}
8787
}

0 commit comments

Comments
 (0)
0