Skip to content

Commit 50a09da

Browse files
committed
fixup bc layer
1 parent e9040b5 commit 50a09da

File tree

6 files changed

+109
-3
lines changed

6 files changed

+109
-3
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ CHANGELOG
66

77
* Allowed configuring taggable cache pools via a new `framework.cache.pools.tags` option (bool|service-id)
88
* Deprecated auto-injection of the container in AbstractController instances, register them as service subscribers instead
9-
* Moved the processing of services tagged `security.expression_language_provider` to the SecurityBundle
9+
* Deprecated the processing of services tagged `security.expression_language_provider` in favor of the new SecurityBundle pass
1010

1111
4.1.0
1212
-----

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
1313

14+
use Symfony\Bundle\SecurityBundle\DependencyInjection\Compiler\AddExpressionLanguageProvidersPass as SecurityExpressionLanguageProvidersPass;
1415
use Symfony\Component\DependencyInjection\ContainerBuilder;
1516
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1617
use Symfony\Component\DependencyInjection\Reference;
@@ -22,6 +23,16 @@
2223
*/
2324
class AddExpressionLanguageProvidersPass implements CompilerPassInterface
2425
{
26+
/**
27+
* @internal
28+
*/
29+
private $handleSecurityLanguageProviders;
30+
31+
public function __construct(bool $handleSecurityLanguageProviders = true)
32+
{
33+
$this->handleSecurityLanguageProviders = $handleSecurityLanguageProviders;
34+
}
35+
2536
/**
2637
* {@inheritdoc}
2738
*/
@@ -34,5 +45,15 @@ public function process(ContainerBuilder $container)
3445
$definition->addMethodCall('addExpressionLanguageProvider', array(new Reference($id)));
3546
}
3647
}
48+
49+
// security
50+
if ($this->handleSecurityLanguageProviders && $container->has('security.expression_language')) {
51+
@trigger_error(sprintf('Registering services tagged with "security.expression_language_provider" is deprecated since Symfony 4.2, use the "%s" instead.', SecurityExpressionLanguageProvidersPass::class), E_USER_DEPRECATED);
52+
53+
$definition = $container->findDefinition('security.expression_language');
54+
foreach ($container->findTaggedServiceIds('security.expression_language_provider', true) as $id => $attributes) {
55+
$definition->addMethodCall('registerProvider', array(new Reference($id)));
56+
}
57+
}
3758
}
3859
}

src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TestServiceContainerRealRefPass;
2828
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\UnusedTagsPass;
2929
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\WorkflowGuardListenerPass;
30+
use Symfony\Bundle\SecurityBundle\DependencyInjection\Compiler\AddExpressionLanguageProvidersPass as SecurityExpressionLanguageProvidersPass;
3031
use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass;
3132
use Symfony\Component\HttpKernel\DependencyInjection\ControllerArgumentValueResolverPass;
3233
use Symfony\Component\HttpKernel\DependencyInjection\LoggerPass;
@@ -101,7 +102,7 @@ public function build(ContainerBuilder $container)
101102
$this->addCompilerPassIfExists($container, AddConsoleCommandPass::class, PassConfig::TYPE_BEFORE_REMOVING);
102103
$this->addCompilerPassIfExists($container, TranslatorPass::class);
103104
$container->addCompilerPass(new LoggingTranslatorPass());
104-
$container->addCompilerPass(new AddExpressionLanguageProvidersPass());
105+
$container->addCompilerPass(new AddExpressionLanguageProvidersPass(!class_exists(SecurityExpressionLanguageProvidersPass::class)));
105106
$this->addCompilerPassIfExists($container, TranslationExtractorPass::class);
106107
$this->addCompilerPassIfExists($container, TranslationDumperPass::class);
107108
$container->addCompilerPass(new FragmentRendererPass());

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

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,86 @@ public function testProcessForRouterAlias()
5757
$this->assertEquals('addExpressionLanguageProvider', $calls[0][0]);
5858
$this->assertEquals(new Reference('some_routing_provider'), $calls[0][1][0]);
5959
}
60+
61+
/**
62+
* @group legacy
63+
*/
64+
public function testProcessForSecurity()
65+
{
66+
$container = new ContainerBuilder();
67+
$container->addCompilerPass(new AddExpressionLanguageProvidersPass());
68+
69+
$definition = new Definition('\stdClass');
70+
$definition->addTag('security.expression_language_provider');
71+
$container->setDefinition('some_security_provider', $definition->setPublic(true));
72+
73+
$container->register('security.expression_language', '\stdClass')->setPublic(true);
74+
$container->compile();
75+
76+
$calls = $container->getDefinition('security.expression_language')->getMethodCalls();
77+
$this->assertCount(1, $calls);
78+
$this->assertEquals('registerProvider', $calls[0][0]);
79+
$this->assertEquals(new Reference('some_security_provider'), $calls[0][1][0]);
80+
}
81+
82+
/**
83+
* @group legacy
84+
*/
85+
public function testProcessForSecurityAlias()
86+
{
87+
$container = new ContainerBuilder();
88+
$container->addCompilerPass(new AddExpressionLanguageProvidersPass());
89+
90+
$definition = new Definition('\stdClass');
91+
$definition->addTag('security.expression_language_provider');
92+
$container->setDefinition('some_security_provider', $definition->setPublic(true));
93+
94+
$container->register('my_security.expression_language', '\stdClass')->setPublic(true);
95+
$container->setAlias('security.expression_language', 'my_security.expression_language');
96+
$container->compile();
97+
98+
$calls = $container->getDefinition('my_security.expression_language')->getMethodCalls();
99+
$this->assertCount(1, $calls);
100+
$this->assertEquals('registerProvider', $calls[0][0]);
101+
$this->assertEquals(new Reference('some_security_provider'), $calls[0][1][0]);
102+
}
103+
104+
/**
105+
* @group legacy
106+
*/
107+
public function testProcessIgnoreSecurity()
108+
{
109+
$container = new ContainerBuilder();
110+
$container->addCompilerPass(new AddExpressionLanguageProvidersPass(false));
111+
112+
$definition = new Definition('\stdClass');
113+
$definition->addTag('security.expression_language_provider');
114+
$container->setDefinition('some_security_provider', $definition->setPublic(true));
115+
116+
$container->register('security.expression_language', '\stdClass')->setPublic(true);
117+
$container->compile();
118+
119+
$calls = $container->getDefinition('security.expression_language')->getMethodCalls();
120+
$this->assertCount(0, $calls);
121+
}
122+
123+
/**
124+
* @group legacy
125+
*/
126+
public function testProcessIgnoreSecurityAlias()
127+
{
128+
$container = new ContainerBuilder();
129+
$container->addCompilerPass(new AddExpressionLanguageProvidersPass(false));
130+
131+
$definition = new Definition('\stdClass');
132+
$definition->addTag('security.expression_language_provider');
133+
$container->setDefinition('some_security_provider', $definition->setPublic(true));
134+
135+
$container->register('my_security.expression_language', '\stdClass')->setPublic(true);
136+
$container->setAlias('security.expression_language', 'my_security.expression_language');
137+
$container->compile();
138+
139+
$calls = $container->getDefinition('my_security.expression_language')->getMethodCalls();
140+
$this->assertCount(0, $calls);
141+
}
60142
}

src/Symfony/Bundle/SecurityBundle/SecurityBundle.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\SecurityBundle;
1313

14+
use Symfony\Bundle\SecurityBundle\DependencyInjection\Compiler\AddExpressionLanguageProvidersPass;
1415
use Symfony\Bundle\SecurityBundle\DependencyInjection\Compiler\RegisterCsrfTokenClearingLogoutHandlerPass;
1516
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\JsonLoginFactory;
1617
use Symfony\Component\HttpKernel\Bundle\Bundle;
@@ -57,6 +58,7 @@ public function build(ContainerBuilder $container)
5758

5859
$extension->addUserProviderFactory(new InMemoryFactory());
5960
$extension->addUserProviderFactory(new LdapFactory());
61+
$container->addCompilerPass(new AddExpressionLanguageProvidersPass());
6062
$container->addCompilerPass(new AddSecurityVotersPass());
6163
$container->addCompilerPass(new AddSessionDomainConstraintPass(), PassConfig::TYPE_BEFORE_REMOVING);
6264
$container->addCompilerPass(new RegisterCsrfTokenClearingLogoutHandlerPass());

src/Symfony/Bundle/SecurityBundle/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"conflict": {
4747
"symfony/var-dumper": "<3.4",
4848
"symfony/event-dispatcher": "<3.4",
49-
"symfony/framework-bundle": "<4.1.1",
49+
"symfony/framework-bundle": "<4.2",
5050
"symfony/console": "<3.4"
5151
},
5252
"autoload": {

0 commit comments

Comments
 (0)