Skip to content

Commit a7c76d8

Browse files
authored
[FrameworkBundle] Allow default cache pools to be overwritten by user
1 parent 589155d commit a7c76d8

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

DependencyInjection/FrameworkExtension.php

+22-20
Original file line numberDiff line numberDiff line change
@@ -307,30 +307,10 @@ public function load(array $configs, ContainerBuilder $container)
307307
}
308308
}
309309

310-
// register cache before session so both can share the connection services
311-
$this->registerCacheConfiguration($config['cache'], $container);
312-
313-
if ($this->isConfigEnabled($container, $config['session'])) {
314-
if (!\extension_loaded('session')) {
315-
throw new LogicException('Session support cannot be enabled as the session extension is not installed. See https://php.net/session.installation for instructions.');
316-
}
317-
318-
$this->sessionConfigEnabled = true;
319-
$this->registerSessionConfiguration($config['session'], $container, $loader);
320-
if (!empty($config['test'])) {
321-
$container->getDefinition('test.session.listener')->setArgument(1, '%session.storage.options%');
322-
}
323-
}
324-
325310
if ($this->isConfigEnabled($container, $config['request'])) {
326311
$this->registerRequestConfiguration($config['request'], $container, $loader);
327312
}
328313

329-
if (null === $config['csrf_protection']['enabled']) {
330-
$config['csrf_protection']['enabled'] = $this->sessionConfigEnabled && !class_exists(FullStack::class) && ContainerBuilder::willBeAvailable('symfony/security-csrf', CsrfTokenManagerInterface::class, ['symfony/framework-bundle']);
331-
}
332-
$this->registerSecurityCsrfConfiguration($config['csrf_protection'], $container, $loader);
333-
334314
if ($this->isConfigEnabled($container, $config['form'])) {
335315
if (!class_exists(Form::class)) {
336316
throw new LogicException('Form support cannot be enabled as the Form component is not installed. Try running "composer require symfony/form".');
@@ -459,6 +439,28 @@ public function load(array $configs, ContainerBuilder $container)
459439
$this->registerUidConfiguration($config['uid'], $container, $loader);
460440
}
461441

442+
// register cache & dependencies last so that user-defined cache pools take precedence over the default pools created above (e.g. in rate_limiter, validation)
443+
$this->registerCacheConfiguration($config['cache'], $container);
444+
445+
// register session after cache so both can share the connection services
446+
if ($this->isConfigEnabled($container, $config['session'])) {
447+
if (!\extension_loaded('session')) {
448+
throw new LogicException('Session support cannot be enabled as the session extension is not installed. See https://php.net/session.installation for instructions.');
449+
}
450+
451+
$this->sessionConfigEnabled = true;
452+
$this->registerSessionConfiguration($config['session'], $container, $loader);
453+
if (!empty($config['test'])) {
454+
$container->getDefinition('test.session.listener')->setArgument(1, '%session.storage.options%');
455+
}
456+
}
457+
458+
// csrf depends on session being registered
459+
if (null === $config['csrf_protection']['enabled']) {
460+
$config['csrf_protection']['enabled'] = $this->sessionConfigEnabled && !class_exists(FullStack::class) && ContainerBuilder::willBeAvailable('symfony/security-csrf', CsrfTokenManagerInterface::class, ['symfony/framework-bundle']);
461+
}
462+
$this->registerSecurityCsrfConfiguration($config['csrf_protection'], $container, $loader);
463+
462464
$this->addAnnotatedClassesToCompile([
463465
'**\\Controller\\',
464466
'**\\Entity\\',

0 commit comments

Comments
 (0)