Skip to content

Commit 6ad6189

Browse files
committed
Merge branch '5.3' into 5.4
* 5.3: Use GitHub issue form templates Add missing translations for Persian (fa) Add the missing translations for Bahasa Indonesia (id) Update README.md Fix deprecations on PHP 8.2 [DependencyInjection] Fix autowiring tagged arguments from attributes Fix commands when local vault is disabled [Lock] Fix incorrect return type in PostgreSqlStore
2 parents 1670d78 + be833dd commit 6ad6189

File tree

4 files changed

+36
-9
lines changed

4 files changed

+36
-9
lines changed

Compiler/AutowirePass.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,8 @@ private function autowireCalls(\ReflectionClass $reflectionClass, bool $isRoot,
163163
$this->decoratedClass = null;
164164
$this->getPreviousValue = null;
165165

166-
if ($isRoot && ($definition = $this->container->getDefinition($this->currentId)) && ($decoratedDefinition = $definition->getDecoratedService()) && null !== ($innerId = $decoratedDefinition[0]) && $this->container->has($innerId)) {
167-
// If the class references to itself and is decorated, provide the inner service id and class to not get a circular reference
168-
$this->decoratedClass = $this->container->findDefinition($innerId)->getClass();
169-
$this->decoratedId = $decoratedDefinition[1] ?? $this->currentId.'.inner';
166+
if ($isRoot && ($definition = $this->container->getDefinition($this->currentId)) && null !== ($this->decoratedId = $definition->innerServiceId) && $this->container->has($this->decoratedId)) {
167+
$this->decoratedClass = $this->container->findDefinition($this->decoratedId)->getClass();
170168
}
171169

172170
$patchedIndexes = [];

Compiler/PassConfig.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,11 @@ public function __construct()
6262
new AutowireRequiredMethodsPass(),
6363
new AutowireRequiredPropertiesPass(),
6464
new ResolveBindingsPass(),
65+
new ServiceLocatorTagPass(),
66+
new DecoratorServicePass(),
6567
new CheckDefinitionValidityPass(),
6668
new AutowirePass(false),
6769
new ServiceLocatorTagPass(),
68-
new DecoratorServicePass(),
6970
new ResolveTaggedIteratorArgumentPass(),
7071
new ResolveServiceSubscribersPass(),
7172
new ResolveReferencesToAliasesPass(),

Tests/Compiler/AutowirePassTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,8 +1027,8 @@ public function testAutowireDecorator()
10271027
->setAutowired(true)
10281028
;
10291029

1030-
(new AutowirePass())->process($container);
10311030
(new DecoratorServicePass())->process($container);
1031+
(new AutowirePass())->process($container);
10321032

10331033
$definition = $container->getDefinition(Decorator::class);
10341034
$this->assertSame(Decorator::class.'.inner', (string) $definition->getArgument(1));
@@ -1050,8 +1050,8 @@ public function testAutowireDecoratorChain()
10501050
->setAutowired(true)
10511051
;
10521052

1053-
(new AutowirePass())->process($container);
10541053
(new DecoratorServicePass())->process($container);
1054+
(new AutowirePass())->process($container);
10551055

10561056
$definition = $container->getDefinition(DecoratedDecorator::class);
10571057
$this->assertSame(DecoratedDecorator::class.'.inner', (string) $definition->getArgument(0));
@@ -1068,8 +1068,8 @@ public function testAutowireDecoratorRenamedId()
10681068
->setAutowired(true)
10691069
;
10701070

1071-
(new AutowirePass())->process($container);
10721071
(new DecoratorServicePass())->process($container);
1072+
(new AutowirePass())->process($container);
10731073

10741074
$definition = $container->getDefinition(Decorator::class);
10751075
$this->assertSame('renamed', (string) $definition->getArgument(1));
@@ -1086,11 +1086,12 @@ public function testDoNotAutowireDecoratorWhenSeveralArgumentOfTheType()
10861086
->setAutowired(true)
10871087
;
10881088

1089+
(new DecoratorServicePass())->process($container);
10891090
try {
10901091
(new AutowirePass())->process($container);
10911092
$this->fail('AutowirePass should have thrown an exception');
10921093
} catch (AutowiringFailedException $e) {
1093-
$this->assertSame('Cannot autowire service "Symfony\Component\DependencyInjection\Tests\Compiler\NonAutowirableDecorator": argument "$decorated1" of method "__construct()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\DecoratorInterface" but no such service exists. You should maybe alias this interface to one of these existing services: "Symfony\Component\DependencyInjection\Tests\Compiler\Decorated", "Symfony\Component\DependencyInjection\Tests\Compiler\NonAutowirableDecorator".', (string) $e->getMessage());
1094+
$this->assertSame('Cannot autowire service "Symfony\Component\DependencyInjection\Tests\Compiler\NonAutowirableDecorator": argument "$decorated1" of method "__construct()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\DecoratorInterface" but no such service exists. You should maybe alias this interface to one of these existing services: "Symfony\Component\DependencyInjection\Tests\Compiler\NonAutowirableDecorator", "Symfony\Component\DependencyInjection\Tests\Compiler\NonAutowirableDecorator.inner".', (string) $e->getMessage());
10941095
}
10951096
}
10961097

Tests/Compiler/IntegrationTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,33 @@ public function testCanDecorateServiceLocator()
186186
$this->assertSame($container->get('foo'), $container->get(DecoratedServiceLocator::class)->get('foo'));
187187
}
188188

189+
public function testAliasDecoratedService()
190+
{
191+
$container = new ContainerBuilder();
192+
193+
$container->register('service', ServiceLocator::class)
194+
->setPublic(true)
195+
->setArguments([[]])
196+
;
197+
$container->register('decorator', DecoratedServiceLocator::class)
198+
->setDecoratedService('service')
199+
->setAutowired(true)
200+
->setPublic(true)
201+
;
202+
$container->setAlias(ServiceLocator::class, 'decorator.inner')
203+
->setPublic(true)
204+
;
205+
$container->register('user_service', DecoratedServiceLocator::class)
206+
->setAutowired(true)
207+
;
208+
209+
$container->compile();
210+
211+
$this->assertInstanceOf(DecoratedServiceLocator::class, $container->get('service'));
212+
$this->assertInstanceOf(ServiceLocator::class, $container->get(ServiceLocator::class));
213+
$this->assertSame($container->get('service'), $container->get('decorator'));
214+
}
215+
189216
/**
190217
* @dataProvider getYamlCompileTests
191218
*/

0 commit comments

Comments
 (0)