Skip to content

Commit f8c01b0

Browse files
committed
feature #34884 [DI] Enable auto alias compiler pass by default (X-Coder264)
This PR was merged into the 5.1-dev branch. Discussion ---------- [DI] Enable auto alias compiler pass by default | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | | Deprecations? | no | Tickets | Fix #34194 | License | MIT | Doc PR | I'm sending this PR to trigger a discussion as @nicolas-grekas suggested in #34194 I'm using this quite a lot in one of my applications and I don't see any reasons why it shouldn't be enabled by default. Commits ------- 4fde51745b Enable auto alias compiler pass by default
2 parents 1867cd1 + ef4ae2b commit f8c01b0

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

Compiler/PassConfig.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public function __construct()
4949
];
5050

5151
$this->optimizationPasses = [[
52+
new AutoAliasServicePass(),
5253
new ValidateEnvPlaceholdersPass(),
5354
new ResolveChildDefinitionsPass(),
5455
new RegisterServiceSubscribersPass(),

Tests/ContainerBuilderTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,6 +1601,24 @@ public function testWither()
16011601
$wither = $container->get('wither');
16021602
$this->assertInstanceOf(Foo::class, $wither->foo);
16031603
}
1604+
1605+
public function testAutoAliasing()
1606+
{
1607+
$container = new ContainerBuilder();
1608+
$container->register(C::class);
1609+
$container->register(D::class);
1610+
1611+
$container->setParameter('foo', D::class);
1612+
1613+
$definition = new Definition(X::class);
1614+
$definition->setPublic(true);
1615+
$definition->addTag('auto_alias', ['format' => '%foo%']);
1616+
$container->setDefinition(X::class, $definition);
1617+
1618+
$container->compile();
1619+
1620+
$this->assertInstanceOf(D::class, $container->get(X::class));
1621+
}
16041622
}
16051623

16061624
class FooClass
@@ -1617,3 +1635,15 @@ public function __construct(A $a)
16171635
{
16181636
}
16191637
}
1638+
1639+
interface X
1640+
{
1641+
}
1642+
1643+
class C implements X
1644+
{
1645+
}
1646+
1647+
class D implements X
1648+
{
1649+
}

0 commit comments

Comments
 (0)