From 8d60396e0eba9feeeab56d6d2e54485e978e5bef Mon Sep 17 00:00:00 2001 From: Hugo Hamon Date: Fri, 9 Jan 2015 16:56:14 +0100 Subject: [PATCH] [FrameworkBundle|TwigBundle] update functional tests configuration files to not use deprecated config keys anymore. --- .../DependencyInjection/Configuration.php | 10 ++++++++++ .../DependencyInjection/FrameworkExtension.php | 1 - .../Tests/DependencyInjection/Fixtures/php/csrf.php | 8 ++------ .../DependencyInjection/FrameworkExtensionTest.php | 2 +- .../TwigBundle/DependencyInjection/Configuration.php | 12 ++++++++++-- 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index ed2f3ab97c56e..4edb96e9d3c44 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -43,6 +43,16 @@ public function getConfigTreeBuilder() $rootNode = $treeBuilder->root('framework'); $rootNode + // Check deprecations before the config is processed to ensure + // the setting has been explicitly defined in a configuration file. + ->beforeNormalization() + ->ifTrue(function ($v) { return isset($v['csrf_protection']['field_name']); }) + ->then(function ($v) { + trigger_error('The framework.csrf_protection.field_name configuration key is deprecated since version 2.4 and will be removed in 3.0. Use the framework.form.csrf_protection.field_name configuration key instead', E_USER_DEPRECATED); + + return $v; + }) + ->end() ->children() ->scalarNode('secret')->end() ->scalarNode('http_method_override') diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 590c262c665c4..fdcd1be7fe168 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -205,7 +205,6 @@ private function registerFormConfiguration($config, ContainerBuilder $container, if (null !== $config['form']['csrf_protection']['field_name']) { $container->setParameter('form.type_extension.csrf.field_name', $config['form']['csrf_protection']['field_name']); } else { - trigger_error('The framework.csrf_protection.field_name configuration key is deprecated since version 2.4 and will be removed in 3.0. Use the framework.form.csrf_protection.field_name configuration key instead', E_USER_DEPRECATED); $container->setParameter('form.type_extension.csrf.field_name', $config['csrf_protection']['field_name']); } } else { diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/csrf.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/csrf.php index ff5286c7a2c62..0c34ad10892d9 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/csrf.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/csrf.php @@ -1,14 +1,10 @@ loadFromExtension('framework', array( - 'csrf_protection' => array( - 'enabled' => false, - ), + 'csrf_protection' => true, 'form' => array( 'enabled' => true, - 'csrf_protection' => array( - 'enabled' => true, - ), + 'csrf_protection' => true, ), 'session' => array( 'handler_id' => null, diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 4050bf13fec8f..48e96c3cedb64 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -467,7 +467,7 @@ public function testLegacyFormCsrfFieldNameCanBeSetUnderCsrfSettings() $this->assertEquals('_custom', $container->getParameter('form.type_extension.csrf.field_name')); } - public function testFormCsrfFieldNameUnderFormSettingsTakesPrecedence() + public function testLegacyFormCsrfFieldNameUnderFormSettingsTakesPrecedence() { $container = $this->createContainerFromFile('form_csrf_under_form_sets_field_name'); diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php index ac6059738e759..4ac0847707158 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php @@ -49,13 +49,21 @@ public function getConfigTreeBuilder() private function addFormSection(ArrayNodeDefinition $rootNode) { $rootNode + // Check deprecation before the config is processed to ensure + // the setting has been explicitly defined in a configuration file. + ->beforeNormalization() + ->ifTrue(function ($v) { return isset($v['form']['resources']); }) + ->then(function ($v) { + trigger_error('The twig.form.resources configuration key is deprecated since version 2.6 and will be removed in 3.0. Use the twig.form_themes configuration key instead.', E_USER_DEPRECATED); + + return $v; + }) + ->end() ->validate() ->ifTrue(function ($v) { return count($v['form']['resources']) > 0; }) ->then(function ($v) { - trigger_error('The twig.form.resources configuration key is deprecated since version 2.6 and will be removed in 3.0. Use the twig.form_themes configuration key instead.', E_USER_DEPRECATED); - $v['form_themes'] = array_values(array_unique(array_merge($v['form']['resources'], $v['form_themes']))); return $v;