Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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

Merged
fabpot merged 1 commit intosymfony:masterfromalekitto:master
Oct 10, 2018

Conversation

@alekitto
Copy link
Contributor

QA
Branch?master
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#26287
LicenseMIT
Doc PRTBD

In order to allow HTTP methods other than GET, PUT, POST, DELETE and PATCH, theallowed_methods option underframework.form configuration has been added.
This configuration option adds the specified methods to theFormConfigBuilder whitelist, allowing that methods be used in form configuration viasetMethod or themethod 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.

@vudaltsov
Copy link
Contributor

Can we just remove thatin_array check? As far as I can see it's not influencing anything internally...
It could be a question of security but it should be solved not by forms but by server configuration.

}

if ($this->container->hasParameter('form.allowed_methods')) {
FormConfigBuilder::setAllowedMethods($this->container->getParameter('form.allowed_methods'));

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?

Copy link
ContributorAuthor

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?

@alekittoalekittoforce-pushed themaster branch 3 times, most recently from4b82548 to4f5ab03CompareMarch 19, 2018 23:35
@vudaltsov
Copy link
Contributor

What if if we move the check fromsetMethod() to$optionsResolver->setAllowedValues('method', [])?

This will give developers a possibility to write an extension for theFormType with$resolver->addAllowedValues('method', ['RESET']) and everyone will be happy :)

@nicolas-grekasnicolas-grekas modified the milestones:4.1,nextApr 20, 2018
Copy link
Member

@xabbuhxabbuh left a 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.

@alekittoalekittoforce-pushed themaster branch 4 times, most recently from3e2a477 to227da93CompareAugust 28, 2018 13:35
<!-- FormFactory-->
<serviceid="form.factory"class="Symfony\Component\Form\FormFactory"public="true">
<argumenttype="service"id="form.registry" />
<argumenttype="service"id="form.resolved_type_factory" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

for 3.4?

Copy link
ContributorAuthor

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?

Copy link
Member

@xabbuhxabbuhSep 1, 2018
edited
Loading

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
Copy link
Contributor

@alekitto , why don't you like my solution? Forms have a clear extension mechanism - that isOptionsResolver. Let's use it here!

@alekitto
Copy link
ContributorAuthor

@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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

private const?

@vudaltsov
Copy link
Contributor

@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);
Copy link
Member

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);});

alekitto reacted with thumbs up emoji
@yceruto
Copy link
Member

yceruto commentedAug 30, 2018
edited
Loading

My doubt at this point:setMethod() will accept any custom value butmethod option only the allowed by default, why not open this option too? (i.e. without allowed values) Otherwise, these paths are inconsistent (according to previous behavior).

@alekitto
Copy link
ContributorAuthor

@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
Copy link
Member

@alekitto Yes, I agree, but this proposal opensetMethod() without restriction...and if we can do this now:

$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
Copy link
ContributorAuthor

@yceruto You've got a point. I'm still thinking that the best option is to remove the checks and suggest toalways useRequest::METHOD_* constants to avoid misspelling. 

@yceruto
Copy link
Member

@alekitto I bet on that too 👍

@vudaltsov
Copy link
Contributor

So you suggest one check insetMethod() doingin_array($upperCasedMethod, [Request::METHOD_HEAD...])?

@yceruto
Copy link
Member

@vudaltsov I understood:remove the checks at all and documenting:**suggest** to always use Request::METHOD_* constants to avoid misspelling..

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
Copy link
Member

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
Copy link
ContributorAuthor

@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.
In fact, it simply definesmethod = token and then lists some standardized methods.

@xabbuh
Copy link
Member

@alekitto Can you also add an entry to the component's changelog file?

@alekitto
Copy link
ContributorAuthor

alekitto commentedOct 9, 2018
edited
Loading

@xabbuh Ok, done 👍

Copy link
Member

@fabpotfabpot left a 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

HTTP instead of http

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Changed

@xabbuh
Copy link
Member

The build failure is not related, but requires a fix on how we run tests on Travis CI (#28788 or something like that).

@fabpot
Copy link
Member

Thank you@alekitto.

@fabpotfabpot merged commit27d228c intosymfony:masterOct 10, 2018
fabpot added a commit that referenced this pull requestOct 10, 2018
…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
@nicolas-grekasnicolas-grekas modified the milestones:next,4.2Nov 1, 2018
This was referencedNov 3, 2018
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@ycerutoycerutoyceruto left review comments

@nicolas-grekasnicolas-grekasnicolas-grekas requested changes

@fabpotfabpotfabpot approved these changes

@xabbuhxabbuhxabbuh approved these changes

+2 more reviewers

@ro0NLro0NLro0NL left review comments

@vudaltsovvudaltsovvudaltsov approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

4.2

Development

Successfully merging this pull request may close these issues.

8 participants

@alekitto@vudaltsov@yceruto@xabbuh@fabpot@nicolas-grekas@ro0NL@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp