Skip to content

Commit 9226902

Browse files
bug symfony#54547 [HttpKernel] Force non lazy controller services (smnandre)
This PR was submitted for the 6.4 branch but it was merged into the 5.4 branch instead. Discussion ---------- [HttpKernel] Force non lazy controller services | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix symfony#54542 | License | MIT Controllers registered as lazy services created a bug where IsGranted attribute were ignored. Following `@nicolas`-grekas suggestion, this PR enfore that controllers are not registered as lazy. Commits ------- 38d71d6 [HttpKernel] Ensure controllers are not lazy
2 parents 3faeb57 + 38d71d6 commit 9226902

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/Symfony/Component/HttpKernel/DependencyInjection/RegisterControllerArgumentLocatorsPass.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public function process(ContainerBuilder $container)
7070
foreach ($container->findTaggedServiceIds($this->controllerTag, true) as $id => $tags) {
7171
$def = $container->getDefinition($id);
7272
$def->setPublic(true);
73+
$def->setLazy(false);
7374
$class = $def->getClass();
7475
$autowire = $def->isAutowired();
7576
$bindings = $def->getBindings();

src/Symfony/Component/HttpKernel/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Symfony\Component\DependencyInjection\TypedReference;
2626
use Symfony\Component\HttpFoundation\Response;
2727
use Symfony\Component\HttpKernel\DependencyInjection\RegisterControllerArgumentLocatorsPass;
28+
use Symfony\Component\HttpKernel\Tests\Fixtures\DataCollector\DummyController;
2829
use Symfony\Component\HttpKernel\Tests\Fixtures\Suit;
2930

3031
class RegisterControllerArgumentLocatorsPassTest extends TestCase
@@ -285,6 +286,21 @@ public function testControllersAreMadePublic()
285286
$this->assertTrue($container->getDefinition('foo')->isPublic());
286287
}
287288

289+
public function testControllersAreMadeNonLazy()
290+
{
291+
$container = new ContainerBuilder();
292+
$container->register('argument_resolver.service')->addArgument([]);
293+
294+
$container->register('foo', DummyController::class)
295+
->addTag('controller.service_arguments')
296+
->setLazy(true);
297+
298+
$pass = new RegisterControllerArgumentLocatorsPass();
299+
$pass->process($container);
300+
301+
$this->assertFalse($container->getDefinition('foo')->isLazy());
302+
}
303+
288304
/**
289305
* @dataProvider provideBindings
290306
*/

0 commit comments

Comments
 (0)