diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index d11e2d256c2e4..96a5c01063e68 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -93,14 +93,18 @@ public function load(array $configs, ContainerBuilder $container) $loader->load('security.xml'); - $this->registerSecurityCsrfConfiguration($config['csrf_protection'], $container, $loader); - if ($this->isConfigEnabled($container, $config['form'])) { $this->formConfigEnabled = true; $this->registerFormConfiguration($config, $container, $loader); $config['validation']['enabled'] = true; + + if ($this->isConfigEnabled($container, $config['form']['csrf_protection'])) { + $config['csrf_protection']['enabled'] = true; + } } + $this->registerSecurityCsrfConfiguration($config['csrf_protection'], $container, $loader); + if (isset($config['templating'])) { $this->registerTemplatingConfiguration($config['templating'], $config['ide'], $container, $loader); } @@ -159,10 +163,6 @@ private function registerFormConfiguration($config, ContainerBuilder $container, { $loader->load('form.xml'); if ($this->isConfigEnabled($container, $config['form']['csrf_protection'])) { - if (!$this->isConfigEnabled($container, $config['csrf_protection'])) { - throw new \LogicException('CSRF protection needs to be enabled in order to use CSRF protection for forms.'); - } - $loader->load('form_csrf.xml'); $container->setParameter('form.type_extension.csrf.enabled', true); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 969916110fdff..09b14ecf67a46 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -41,13 +41,11 @@ public function testCsrfProtectionNeedsSessionToBeEnabled() $this->createContainerFromFile('csrf_needs_session'); } - /** - * @expectedException \LogicException - * @expectedExceptionMessage CSRF protection needs to be enabled in order to use CSRF protection for forms. - */ - public function testCsrfProtectionForFormsNeedCsrfProtectionToBeEnabled() + public function testCsrfProtectionForFormsEnablesCsrfProtectionAutomatically() { - $this->createContainerFromFile('csrf'); + $container = $this->createContainerFromFile('csrf'); + + $this->assertTrue($container->hasDefinition('security.csrf.token_manager')); } public function testSecureRandomIsAvailableIfCsrfIsDisabled()