Skip to content

Commit

Permalink
feature #34884 [DI] Enable auto alias compiler pass by default (X-Cod…
Browse files Browse the repository at this point in the history
…er264)

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

4fde517 Enable auto alias compiler pass by default
  • Loading branch information
fabpot committed Feb 5, 2020
2 parents 33c294f + 4fde517 commit 3bcf8cb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Expand Up @@ -49,6 +49,7 @@ public function __construct()
];

$this->optimizationPasses = [[
new AutoAliasServicePass(),
new ValidateEnvPlaceholdersPass(),
new ResolveChildDefinitionsPass(),
new RegisterServiceSubscribersPass(),
Expand Down
Expand Up @@ -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
Expand All @@ -1617,3 +1635,15 @@ public function __construct(A $a)
{
}
}

interface X
{
}

class C implements X
{
}

class D implements X
{
}

0 comments on commit 3bcf8cb

Please sign in to comment.