From 817453cff563740dca0d92611d4e522c09b0782a Mon Sep 17 00:00:00 2001 From: Toni Uebernickel Date: Wed, 27 Feb 2013 14:12:14 +0100 Subject: [PATCH] [2.2] add http_method_override option to ease setup --- .../FrameworkBundle/DependencyInjection/Configuration.php | 4 ++++ .../DependencyInjection/FrameworkExtension.php | 2 ++ src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php | 4 ++++ .../Resources/config/schema/symfony-1.0.xsd | 1 + .../Tests/DependencyInjection/ConfigurationTest.php | 1 + .../Tests/DependencyInjection/Fixtures/php/full.php | 1 + .../Tests/DependencyInjection/Fixtures/xml/full.xml | 2 +- .../Tests/DependencyInjection/Fixtures/yml/full.yml | 1 + .../Tests/DependencyInjection/FrameworkExtensionTest.php | 7 +++++++ 9 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index fe3c3501d55e..b4ebfd0b4574 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -52,6 +52,10 @@ public function getConfigTreeBuilder() ->end() ->end() ->scalarNode('secret')->end() + ->scalarNode('http_method_override') + ->info("Set true to enable support for the '_method' request parameter to determine the intended HTTP method on POST requests.") + ->defaultTrue() + ->end() ->scalarNode('trust_proxy_headers')->defaultFalse()->end() // @deprecated, to be removed in 2.3 ->arrayNode('trusted_proxies') ->beforeNormalization() diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 606677f38b4c..f8a0a1ac412e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -66,6 +66,8 @@ public function load(array $configs, ContainerBuilder $container) $container->setParameter('kernel.secret', $config['secret']); } + $container->setParameter('kernel.http_method_override', $config['http_method_override']); + $container->setParameter('kernel.trusted_proxies', $config['trusted_proxies']); // @deprecated, to be removed in 2.3 diff --git a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php index a255d120b9db..5523499db500 100644 --- a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php +++ b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php @@ -46,6 +46,10 @@ public function boot() } elseif ($this->container->getParameter('kernel.trust_proxy_headers')) { Request::trustProxyData(); // @deprecated, to be removed in 2.3 } + + if ($this->container->getParameter('kernel.http_method_override')) { + Request::enableHttpMethodParameterOverride(); + } } public function build(ContainerBuilder $container) diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd index 9ddf20305266..6fa067205b00 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd @@ -24,6 +24,7 @@ + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php index 3c6c0ea47541..7db16658e8e1 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -88,6 +88,7 @@ protected static function getBundleDefaultConfig() { return array( 'charset' => null, + 'http_method_override' => true, 'trust_proxy_headers' => false, 'trusted_proxies' => array(), 'ide' => null, diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php index 27988e2c2ef4..899afe15f3d4 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php @@ -4,6 +4,7 @@ 'secret' => 's3cr3t', 'default_locale' => 'fr', 'form' => null, + 'http_method_override' => false, 'trust_proxy_headers' => true, 'trusted_proxies' => array('127.0.0.1', '10.0.0.1'), 'csrf_protection' => array( diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml index eacd416597ba..806796db77de 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml @@ -6,7 +6,7 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd"> - + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml index 9eddd249d5b9..3707bf1eeb6c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml @@ -2,6 +2,7 @@ framework: secret: s3cr3t default_locale: fr form: ~ + http_method_override: false trust_proxy_headers: true trusted_proxies: ['127.0.0.1', '10.0.0.1'] csrf_protection: diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 00c0098a0dda..0706eb02b36f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -41,6 +41,13 @@ public function testProxies() $this->assertEquals(array('127.0.0.1', '10.0.0.1'), $container->getParameter('kernel.trusted_proxies')); } + public function testHttpMethodOverride() + { + $container = $this->createContainerFromFile('full'); + + $this->assertFalse($container->getParameter('kernel.http_method_override')); + } + public function testEsi() { $container = $this->createContainerFromFile('full');