8000 [Form] allow additional http methods in FormType · symfony/symfony@2f212c8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2f212c8

Browse files
committed
[Form] allow additional http methods in FormType
1 parent 8651758 commit 2f212c8

File tree

4 files changed

+22
-33
lines changed

4 files changed

+22
-33
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/Extension/Core/Type/FormType.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@
24 8000 24

2525
class FormType extends BaseType
2626
{
27+
/**
28+
* The accepted request methods.
29+
*
30+
* @var array
31+
*/
32+
private const ALLOWED_METHODS = array(
33+
'GET',
34+
'PUT',
35+
'POST',
36+
'DELETE',
37+
'PATCH',
38+
);
39+
2740
private $propertyAccessor;
2841

2942
public function __construct(PropertyAccessorInterface $propertyAccessor = null)
@@ -185,6 +198,14 @@ public function configureOptions(OptionsResolver $resolver)
185198
$resolver->setAllowedTypes('label_attr', 'array');
186199
$resolver->setAllowedTypes('upload_max_size_message', array('callable'));
187200
$resolver->setAllowedTypes('help', array('string', 'null'));
201+
202+
$resolver->setAllowedValues('method', function ($value) {
203+
return \in_array(\strtoupper($value), self::ALLOWED_METHODS);
204+
});
205+
206+
$resolver->setNormalizer('method', function (Options $options, string $value): string {
207+
return \strtoupper($value);
208+
});
188209
}
189210

190211
/**

src/Symfony/Component/Form/FormConfigBuilder.php

Lines changed: 1 addition & 24 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,17 +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(
795-
'The form method is "%s", but should be one of "%s".',
796-
$method,
797-
implode('", "', self::$allowedMethods)
798-
));
799-
}
800-
801-
$this->method = $upperCaseMethod;
778+
$this->method = strtoupper($method);
802779

803780
return $this;
804781
}

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)
0