Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Form] allow additional http methods in form configuration#26324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
vudaltsov commentedFeb 27, 2018
Can we just remove that |
| } | ||
| if ($this->container->hasParameter('form.allowed_methods')) { | ||
| FormConfigBuilder::setAllowedMethods($this->container->getParameter('form.allowed_methods')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I would suggest to try hardernot using any global state for this feature.
Could be just an option forFormConfigBuilder maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
FormConfigBuilder is not instantiated by the DI container, but by theResolvedFormType class which is created byResolvedFormTypeFactory, so the injection of a parameter is too cumbersome. I tried to create a TypeExtension to inject the parameter as an option, but it can be overridden on any form type (this means that we can pass method and allowed methods as options and it I don't think it makes sense).
Now i tried to inject the allowed methods directly in the form factory which is set into theFormConfigBuilder. What do you think about this solution?
4b82548 to4f5ab03Comparevudaltsov commentedMar 20, 2018
What if if we move the check from This will give developers a possibility to write an extension for the |
xabbuh left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
The solution suggested by@vudaltsov looks much better to me.
3e2a477 to227da93Compare| <!-- FormFactory--> | ||
| <serviceid="form.factory"class="Symfony\Component\Form\FormFactory"public="true"> | ||
| <argumenttype="service"id="form.registry" /> | ||
| <argumenttype="service"id="form.resolved_type_factory" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
for 3.4?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
The second constructor parameter was deleted in3607eb3 (included in 3.3 beta 1).
Should I restore it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I think@ro0NL meant that this change could probably be made on a lower version of the FrameworkBundle too (i.e. all versions that do not support the Form component in version 3.2 or lower).
vudaltsov commentedAug 29, 2018
@alekitto , why don't you like my solution? Forms have a clear extension mechanism - that is |
alekitto commentedAug 29, 2018
@vudaltsov in fact i’ve used it in my last revision. I moved the allowedMethods const in FormType and used it to set the ‘method’ option allowed values |
| * | ||
| * @var array | ||
| */ | ||
| privatestatic$allowedMethods =array( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
private const?
vudaltsov commentedAug 29, 2018
@alekitto , I am so sorry, I missed that! Thank you :) |
| $resolver->setAllowedTypes('upload_max_size_message',array('callable')); | ||
| $resolver->setAllowedTypes('help',array('string','null')); | ||
| $resolver->setAllowedValues('method',self::$allowedMethods); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
You can work around with a closure function to avoid duplicated values ([lower|upper]case) in$allowedMethods:
$resolver->setAllowedValues('method',function ($value) {return\in_array($value,self::$allowedMethods);});
Uh oh!
There was an error while loading.Please reload this page.
yceruto commentedAug 30, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
My doubt at this point: |
alekitto commentedAug 30, 2018
@yceruto My first proposal on the issue was to remove the check entirely. You can find the reason for maintaining these checks inthis comment |
yceruto commentedAug 30, 2018
@alekitto Yes, I agree, but this proposal open $this->createFormBuilder()->setMethod('RESET'); why can't I do this too (without add a type extension): $this->createFormBuilder(null, ['method' =>'RESET']); ? Note that the first alternative doesn't comply with theref comment. |
alekitto commentedAug 31, 2018
@yceruto You've got a point. I'm still thinking that the best option is to remove the checks and suggest toalways use |
yceruto commentedAug 31, 2018
@alekitto I bet on that too 👍 |
vudaltsov commentedAug 31, 2018
So you suggest one check in |
yceruto commentedAug 31, 2018
@vudaltsov I understood: Is there any restriction to use a custom request method in HTTP world? if no: IMHO, it is not worth sacrificing this natural possibility in favor of the DX misspelling feature. |
xabbuh commentedSep 1, 2018
Technically the standard IIRC does not make any restriction on which HTTP methods you can use. There are some defined in the RFCs for which you are able to infer some semantics but that doesn't stop you from using your own methods. So maybe just removing the check here is the way to go. |
alekitto commentedSep 1, 2018
@xabbuh Correct. The RFC 7231 defines some method names (GET, HEAD, POST, PUT, DELETE, CONNECT, OPTIONS, TRACE) and others have been registered in different RFCs, but does not restrict method names at all. |
xabbuh commentedOct 9, 2018
@alekitto Can you also add an entry to the component's changelog file? |
alekitto commentedOct 9, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@xabbuh Ok, done 👍 |
fabpot left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
with a minor comment
| * deprecated calling`FormRenderer::searchAndRenderBlock` for fields which were already rendered | ||
| * added a cause when a CSRF error has occurred | ||
| * deprecated the`scale` option of the`IntegerType` | ||
| * removed restriction on allowed http methods |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
HTTP instead of http
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Changed
xabbuh commentedOct 10, 2018
The build failure is not related, but requires a fix on how we run tests on Travis CI (#28788 or something like that). |
fabpot commentedOct 10, 2018
Thank you@alekitto. |
…tion (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 | TBDIn 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
In order to allow HTTP methods other than GET, PUT, POST, DELETE and PATCH, the
allowed_methodsoption underframework.formconfiguration has been added.This configuration option adds the specified methods to the
FormConfigBuilderwhitelist, allowing that methods be used in form configuration viasetMethodor themethodoption.The use-case, that has been discussed in#26287, required the usage of custom HTTP method for describing a resource in an API application.