Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DependencyInjection] Non-existent "inner" service when decorated and autowired #43272

@BafS

Description

@BafS

Symfony version(s) affected: > v5.3.4

Description

There is a breaking change since DependencyInjection was updated (patch version !). It works fine from v5.0.0 to v5.3.4 but newer versions have a breaking change with decorated services. It seems it was introduced #42815 because of the pass order.

How to reproduce

<?php
namespace Test;
require_once 'vendor/autoload.php';

$containerBuilder = new \Symfony\Component\DependencyInjection\ContainerBuilder();

class Foo {}
class Bar extends Foo {}
class A {
    public function __construct(Foo $foo) {}
}

$containerBuilder->register('foo', Foo::class);

$containerBuilder->register('bar', Bar::class)->setDecoratedService('foo');
$containerBuilder->setAlias(Foo::class, 'bar.inner');

$containerBuilder->register(A::class)->setAutowired(true);

$containerBuilder->compile();

This code works for versions <= v5.3.4 and is breaking for versions > v5.3.4.

Error: PHP Fatal error: Uncaught Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have requested a non-existent service "bar.inner". in /.../vendor/symfony/dependency-injection/ContainerBuilder.php:979

Possible Solution

Change the pass order that was changed in #42815 (but if I follow correctly it was made to fix #42791 which was made to fix #42347 because autowire arguments were changed in #40406).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions