diff --git a/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php b/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php index 5bbac05d530f9..b93f8e9982b8c 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php @@ -49,6 +49,7 @@ public function __construct() ]; $this->optimizationPasses = [[ + new AutoAliasServicePass(), new ValidateEnvPlaceholdersPass(), new ResolveChildDefinitionsPass(), new RegisterServiceSubscribersPass(), diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php index b508576327201..c790255664ac9 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php @@ -1601,6 +1601,24 @@ public function testWither() $wither = $container->get('wither'); $this->assertInstanceOf(Foo::class, $wither->foo); } + + public function testAutoAliasing() + { + $container = new ContainerBuilder(); + $container->register(C::class); + $container->register(D::class); + + $container->setParameter('foo', D::class); + + $definition = new Definition(X::class); + $definition->setPublic(true); + $definition->addTag('auto_alias', ['format' => '%foo%']); + $container->setDefinition(X::class, $definition); + + $container->compile(); + + $this->assertInstanceOf(D::class, $container->get(X::class)); + } } class FooClass @@ -1617,3 +1635,15 @@ public function __construct(A $a) { } } + +interface X +{ +} + +class C implements X +{ +} + +class D implements X +{ +}