Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 631d718

Browse files
committed
feature #26324 [Form] allow additional http methods in form configuration (alekitto)
This PR was merged into the 4.2-dev branch. Discussion ---------- [Form] allow additional http methods in form configuration | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #26287 | License | MIT | Doc PR | TBD In order to allow HTTP methods other than GET, PUT, POST, DELETE and PATCH, the `allowed_methods` option under `framework.form` configuration has been added. This configuration option adds the specified methods to the `FormConfigBuilder` whitelist, allowing that methods be used in form configuration via `setMethod` or the `method` option. The use-case, that has been discussed in #26287, required the usage of custom HTTP method for describing a resource in an API application. Commits ------- 27d228c [Form] remove restriction on allowed http methods
2 parents 6fbb494 + 27d228c commit 631d718

File tree

4 files changed

+2
-29
lines changed

4 files changed

+2
-29
lines changed

src/Symfony/Bundle/FrameworkBundle/Resources/config/form.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
<!-- FormFactory -->
3030
<service id="form.factory" class="Symfony\Component\Form\FormFactory" public="true">
3131
<argument type="service" id="form.registry" />
32-
<argument type="service" id="form.resolved_type_factory" />
3332
</service>
3433
<service id="Symfony\Component\Form\FormFactoryInterface" alias="form.factory" />
3534

src/Symfony/Component/Form/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ CHANGELOG
3939
* deprecated calling `FormRenderer::searchAndRenderBlock` for fields which were already rendered
4040
* added a cause when a CSRF error has occurred
4141
* deprecated the `scale` option of the `IntegerType`
42+
* removed restriction on allowed HTTP methods
4243

4344
4.1.0
4445
-----

src/Symfony/Component/Form/FormConfigBuilder.php

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,6 @@ class FormConfigBuilder implements FormConfigBuilderInterface
3434
*/
3535
private static $nativeRequestHandler;
3636

37-
/**
38-
* The accepted request methods.
39-
*
40-
* @var array
41-
*/
42-
private static $allowedMethods = array(
43-
'GET',
44-
'PUT',
45-
'POST',
46-
'DELETE',
47-
'PATCH',
48-
);
49-
5037
/**
5138
* @var bool
5239
*/
@@ -788,13 +775,7 @@ public function setMethod($method)
788775
throw new BadMethodCallException('The config builder cannot be modified anymore.');
789776
}
790777

791-
$upperCaseMethod = strtoupper($method);
792-
793-
if (!\in_array($upperCaseMethod, self::$allowedMethods)) {
794-
throw new InvalidArgumentException(sprintf('The form method is "%s", but should be one of "%s".', $method, implode('", "', self::$allowedMethods)));
795-
}
796-
797-
$this->method = $upperCaseMethod;
778+
$this->method = strtoupper($method);
798779

799780
return $this;
800781
}

src/Symfony/Component/Form/Tests/FormConfigTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,6 @@ public function testSetMethodAllowsPatch()
138138
self::assertSame('PATCH', $formConfigBuilder->getMethod());
139139
}
140140

141-
/**
142-
* @expectedException \Symfony\Component\Form\Exception\InvalidArgumentException
143-
*/
144-
public function testSetMethodDoesNotAllowOtherValues()
145-
{
146-
$this->getConfigBuilder()->setMethod('foo');
147-
}
148-
149141
private function getConfigBuilder($name = 'name')
150142
{
151143
$dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock();

0 commit comments

Comments
 (0)