File tree 4 files changed +22
-33
lines changed
Bundle/FrameworkBundle/Resources/config 4 files changed +22
-33
lines changed Original file line number Diff line number Diff line change 29
29
<!-- FormFactory -->
30
30
<service id =" form.factory" class =" Symfony\Component\Form\FormFactory" public =" true" >
31
31
<argument type =" service" id =" form.registry" />
32
- <argument type =" service" id =" form.resolved_type_factory" />
33
32
</service >
34
33
<service id =" Symfony\Component\Form\FormFactoryInterface" alias =" form.factory" />
35
34
Original file line number Diff line number Diff line change 24
8000
24
25
25
class FormType extends BaseType
26
26
{
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
+
27
40
private $ propertyAccessor ;
28
41
29
42
public function __construct (PropertyAccessorInterface $ propertyAccessor = null )
@@ -185,6 +198,14 @@ public function configureOptions(OptionsResolver $resolver)
185
198
$ resolver ->setAllowedTypes ('label_attr ' , 'array ' );
186
199
$ resolver ->setAllowedTypes ('upload_max_size_message ' , array ('callable ' ));
187
200
$ 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
+ });
188
209
}
189
210
190
211
/**
Original file line number Diff line number Diff line change @@ -34,19 +34,6 @@ class FormConfigBuilder implements FormConfigBuilderInterface
34
34
*/
35
35
private static $ nativeRequestHandler ;
36
36
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
-
50
37
/**
51
38
* @var bool
52
39
*/
@@ -788,17 +775,7 @@ public function setMethod($method)
788
775
throw new BadMethodCallException ('The config builder cannot be modified anymore. ' );
789
776
}
790
777
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 );
802
779
803
780
return $ this ;
804
781
}
Original file line number Diff line number Diff line change @@ -138,14 +138,6 @@ public function testSetMethodAllowsPatch()
138
138
self ::assertSame ('PATCH ' , $ formConfigBuilder ->getMethod ());
139
139
}
140
140
141
- /**
142
- * @expectedException \Symfony\Component\Form\Exception\InvalidArgumentException
143
- */
144
- public function testSetMethodDoesNotAllowOtherValues ()
145
- {
146
- $ this ->getConfigBuilder ()->setMethod ('foo ' );
147
- }
148
-
149
141
private function getConfigBuilder ($ name = 'name ' )
150
142
{
151
143
$ dispatcher = $ this ->getMockBuilder ('Symfony\Component\EventDispatcher\EventDispatcherInterface ' )->getMock ();
You can’t perform that action at this time.
0 commit comments