[DI] Fix autowire inner service
This commit is contained in:
parent
cfc112a484
commit
b79d097c2a
@ -144,11 +144,12 @@ class AutowirePass extends AbstractRecursivePass
|
|||||||
*/
|
*/
|
||||||
private function autowireCalls(\ReflectionClass $reflectionClass, bool $isRoot): array
|
private function autowireCalls(\ReflectionClass $reflectionClass, bool $isRoot): array
|
||||||
{
|
{
|
||||||
|
$this->decoratedId = null;
|
||||||
|
$this->decoratedClass = null;
|
||||||
|
$this->getPreviousValue = null;
|
||||||
|
|
||||||
if ($isRoot && ($definition = $this->container->getDefinition($this->currentId)) && $this->container->has($this->decoratedId = $definition->innerServiceId)) {
|
if ($isRoot && ($definition = $this->container->getDefinition($this->currentId)) && $this->container->has($this->decoratedId = $definition->innerServiceId)) {
|
||||||
$this->decoratedClass = $this->container->findDefinition($this->decoratedId)->getClass();
|
$this->decoratedClass = $this->container->findDefinition($this->decoratedId)->getClass();
|
||||||
} else {
|
|
||||||
$this->decoratedId = null;
|
|
||||||
$this->decoratedClass = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->methodCalls as $i => $call) {
|
foreach ($this->methodCalls as $i => $call) {
|
||||||
|
@ -834,6 +834,29 @@ class AutowirePassTest extends TestCase
|
|||||||
$this->assertSame(Decorator::class.'.inner', (string) $definition->getArgument(1));
|
$this->assertSame(Decorator::class.'.inner', (string) $definition->getArgument(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testAutowireDecoratorChain()
|
||||||
|
{
|
||||||
|
$container = new ContainerBuilder();
|
||||||
|
$container->register(LoggerInterface::class, NullLogger::class);
|
||||||
|
$container->register(Decorated::class, Decorated::class);
|
||||||
|
$container
|
||||||
|
->register(Decorator::class, Decorator::class)
|
||||||
|
->setDecoratedService(Decorated::class)
|
||||||
|
->setAutowired(true)
|
||||||
|
;
|
||||||
|
$container
|
||||||
|
->register(DecoratedDecorator::class, DecoratedDecorator::class)
|
||||||
|
->setDecoratedService(Decorated::class)
|
||||||
|
->setAutowired(true)
|
||||||
|
;
|
||||||
|
|
||||||
|
(new DecoratorServicePass())->process($container);
|
||||||
|
(new AutowirePass())->process($container);
|
||||||
|
|
||||||
|
$definition = $container->getDefinition(DecoratedDecorator::class);
|
||||||
|
$this->assertSame(DecoratedDecorator::class.'.inner', (string) $definition->getArgument(0));
|
||||||
|
}
|
||||||
|
|
||||||
public function testAutowireDecoratorRenamedId()
|
public function testAutowireDecoratorRenamedId()
|
||||||
{
|
{
|
||||||
$container = new ContainerBuilder();
|
$container = new ContainerBuilder();
|
||||||
|
@ -373,6 +373,13 @@ class Decorator implements DecoratorInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class DecoratedDecorator implements DecoratorInterface
|
||||||
|
{
|
||||||
|
public function __construct(DecoratorInterface $decorator)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class NonAutowirableDecorator implements DecoratorInterface
|
class NonAutowirableDecorator implements DecoratorInterface
|
||||||
{
|
{
|
||||||
public function __construct(LoggerInterface $logger, DecoratorInterface $decorated1, DecoratorInterface $decorated2)
|
public function __construct(LoggerInterface $logger, DecoratorInterface $decorated1, DecoratorInterface $decorated2)
|
||||||
|
Reference in New Issue
Block a user