Skip to content

[DI] Decorated service with autowiring broken in 5.3.7 #42803

Closed
@mhujer

Description

@mhujer

Symfony version(s) affected: 5.3.7

Description
Service which decorates another one and uses autowiring is broken after upgrading to 5.3.7.

It was broken by #42347

How to reproduce
Have a decorated service:

use Symfony\Bundle\FrameworkBundle\Routing\Router;
use Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface;
use Symfony\Component\Routing\RouterInterface;

final class FancyUrlRouter implements RouterInterface, WarmableInterface
{

    private Router $router;

    public function __construct(
        Router $router
    )
    {
        $this->router = $router;
    }

configured this way in services.yaml:

    App\Infra\FancyUrl\FancyUrlRouter:
        decorates: 'router'

Works fine with symfony/dependency-injection 5.3.4, but after upgrading it to 5.3.7 it breaks with:

Cannot autowire service "App\FancyUrl\FancyUrlRouter": argument "$router" of method "__construct()" references class "Symfony\Bundle\FrameworkBundle\Routing\Router" but no such service exists. Try changing the type-hint to one of its parents: interface "Symfony\Component\Routing\RouterInterface", interface "Symfony\Component\Routing\RequestContextAwareInterface", interface "Symfony\Component\Routing\Generator\UrlGeneratorInterface", or interface "Symfony\Component\Routing\Matcher\UrlMatcherInterface".

Possible Solution
Revert the change in #42347 (the application works after manually reverting the change in src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php).

Additional context

My guess is that the DecoratorServicePass must be before AutowirePass to prevent AutowirePass from attempting to autowire parameters that should be decorated.

https://github.com/symfony/symfony/pull/42347/files#diff-b75bcd1c8a876c4e6f189c298e7c7133d1d3bc87e2a2876c40ab92a51df1093aR62-R71

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