Skip to content

Commit 2cdeae5

Browse files
committed
bug #13336 Make that AddExpressionLanguageProviderPass works with aliases (maarekj, jakzal)
This PR was merged into the 2.7 branch. Discussion ---------- Make that AddExpressionLanguageProviderPass works with aliases | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #12847 | License | MIT | Doc PR | Replaces #12982 by @maarekj (includes his commit). Commits ------- 16a22cd [FrameworkBundle] Add a test case for service aliases used with AddExpressionLanguageProviderPass. fd97cef [FrameworkBundle] fixed #12847 AddExpressionLanguageProviderPass
2 parents c7bee8f + 16a22cd commit 2cdeae5

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddExpressionLanguageProvidersPass.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ class AddExpressionLanguageProvidersPass implements CompilerPassInterface
2828
public function process(ContainerBuilder $container)
2929
{
3030
// routing
31-
if ($container->hasDefinition('router')) {
31+
if ($container->has('router')) {
3232
$definition = $container->findDefinition('router');
3333
foreach ($container->findTaggedServiceIds('routing.expression_language_provider') as $id => $attributes) {
3434
$definition->addMethodCall('addExpressionLanguageProvider', array(new Reference($id)));
3535
}
3636
}
3737

3838
// security
39-
if ($container->hasDefinition('security.access.expression_voter')) {
39+
if ($container->has('security.access.expression_voter')) {
4040
$definition = $container->findDefinition('security.access.expression_voter');
4141
foreach ($container->findTaggedServiceIds('security.expression_language_provider') as $id => $attributes) {
4242
$definition->addMethodCall('addExpressionLanguageProvider', array(new Reference($id)));

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/AddExpressionLanguageProvidersPassTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,26 @@ public function testProcessForRouter()
3737
$this->assertEquals(new Reference('some_routing_provider'), $calls[0][1][0]);
3838
}
3939

40+
public function testProcessForRouterAlias()
41+
{
42+
$container = new ContainerBuilder();
43+
$container->addCompilerPass(new AddExpressionLanguageProvidersPass());
44+
45+
$definition = new Definition('Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\TestProvider');
46+
$definition->addTag('routing.expression_language_provider');
47+
$container->setDefinition('some_routing_provider', $definition);
48+
49+
$container->register('my_router', '\stdClass');
50+
$container->setAlias('router', 'my_router');
51+
$container->compile();
52+
53+
$router = $container->getDefinition('my_router');
54+
$calls = $router->getMethodCalls();
55+
$this->assertCount(1, $calls);
56+
$this->assertEquals('addExpressionLanguageProvider', $calls[0][0]);
57+
$this->assertEquals(new Reference('some_routing_provider'), $calls[0][1][0]);
58+
}
59+
4060
public function testProcessForSecurity()
4161
{
4262
$container = new ContainerBuilder();
@@ -55,6 +75,26 @@ public function testProcessForSecurity()
5575
$this->assertEquals('addExpressionLanguageProvider', $calls[0][0]);
5676
$this->assertEquals(new Reference('some_security_provider'), $calls[0][1][0]);
5777
}
78+
79+
public function testProcessForSecurityAlias()
80+
{
81+
$container = new ContainerBuilder();
82+
$container->addCompilerPass(new AddExpressionLanguageProvidersPass());
83+
84+
$definition = new Definition('Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\TestProvider');
85+
$definition->addTag('security.expression_language_provider');
86+
$container->setDefinition('some_security_provider', $definition);
87+
88+
$container->register('my_security.access.expression_voter', '\stdClass');
89+
$container->setAlias('security.access.expression_voter', 'my_security.access.expression_voter');
90+
$container->compile();
91+
92+
$router = $container->getDefinition('my_security.access.expression_voter');
93+
$calls = $router->getMethodCalls();
94+
$this->assertCount(1, $calls);
95+
$this->assertEquals('addExpressionLanguageProvider', $calls[0][0]);
96+
$this->assertEquals(new Reference('some_security_provider'), $calls[0][1][0]);
97+
}
5898
}
5999

60100
class TestProvider

0 commit comments

Comments
 (0)