Description
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.