8000 [OptionsResolver] Choose policy on unknown options by iamluc · Pull Request #9754 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[OptionsResolver] Choose policy on unknown options #9754

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

iamluc
Copy link
Contributor
@iamluc iamluc commented Dec 13, 2013

Hi,

This commit adds the possibility to choose a policy on unknown options :

  • required : like before, throw exception (default to keep BC)
  • remove : remove options and do not throw exception
  • ignore : keep options and do not throw exception
Q A
Bug fix? no
New feature? yes
BC breaks? yes
Deprecations? no
Tests pass? yes
Fixed tickets #7979
License MIT
Doc PR

@COil
Copy link
Contributor
COil commented Dec 13, 2013

👍

if (!in_array($unknowOptionPolicy, array(
self::UNKNOWN_OPTION_POLICY_REQUIRE,
self::UNKNOWN_OPTION_POLICY_REMOVE,
self::UNKNOWN_OPTION_POLICY_IGNORE,
Copy link
Member

Choose a reason for hiding this comment

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

please keep them on 1 line

@iamluc
Copy link
Contributor Author
iamluc commented Dec 13, 2013

Updated according to comments

*
* @param array $options An list of option names as keys.
*
* @return array $options with all unknown options removed
Copy link
Contributor

Choose a reason for hiding this comment

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

$options is superflu here

@Koc
Copy link
Contributor
Koc commented Dec 13, 2013

Replaces #7985 , fix #7979?

@kbond
Copy link
Member
kbond commented Dec 13, 2013

Yes, this looks great!

@iamluc
Copy link
Contributor Author
iamluc commented Dec 13, 2013

Fix phpdoc as suggested by pborreli + add public method setUnknownOptionPolicy($unknownOptionPolicy)

@pborreli
Copy link
Contributor

@iamluc you should fix your git username (vieilles instead of iamluc) https://help.github.com/articles/setting-your-username-in-git and fix with git commit --amend --author "New Author Name <email@address.com>"

@iamluc
Copy link
Contributor Author
iamluc commented Dec 13, 2013

@pborreli thanks ! done.

@stof
Copy link
Member
stof commented Dec 13, 2013

I don't think we should have a mutator for this policy: the code instantiating the resolver should control the behavior it expects for unknown options. External code receiceving it to configure default options should not be able to change the policy IMO

@iamluc
Copy link
Contributor Author
iamluc commented Dec 13, 2013

@stof OK, i will revert this.
Do you prefer that I change the method to private or moving the code back in the constructor ?

@stof
Copy link
Member
stof commented Dec 14, 2013

@iamluc move it back to the constructor IMO

@webmozart
Copy link
Contributor

I would prefer if this functionality was configurable in the resolve() method, for example through a parameter $flags:

public function resolve(array $options = array(), $flags = 0);

Example usage:

$options = $resolver->resolve($usersOptions, OptionsResolverInterface::REMOVE_UNKNOWN);

{
$this->defaultOptions = new Options();
if (!in_array($unknownOptionPolicy, array(self::UNKNOWN_OPTION_POLICY_REQUIRE, self::UNKNOWN_OPTION_POLICY_REMOVE, self::UNKNOWN_OPTION_POLICY_IGNORE))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

you need to set the third argument (strict) to true, otherwise '1' would go throught but fail later

@iamluc
Copy link
Contributor Author
iamluc commented Dec 17, 2013

@bschussek PR updated. Is now BC because we changed Interface

if ($flags & OptionsResolverInterface::REMOVE_UNKNOWN) {
$options = $this->removeUnknownOptions($options);
}
elseif (!($flags & OptionsResolverInterface::IGNORE_UNKNOWN)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

must be on the same line as the }

@fabpot
Copy link
Member
fabpot commented Feb 22, 2014

What is the status of this PR? @webmozart Can you check the latest version of the code?

@webmozart
Copy link
Contributor

Replaced by #10574.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0