-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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
[OptionsResolver] Choose policy on unknown options #9754
Conversation
👍 |
if (!in_array($unknowOptionPolicy, array( | ||
self::UNKNOWN_OPTION_POLICY_REQUIRE, | ||
self::UNKNOWN_OPTION_POLICY_REMOVE, | ||
self::UNKNOWN_OPTION_POLICY_IGNORE, |
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.
please keep them on 1 line
Updated according to comments |
* | ||
* @param array $options An list of option names as keys. | ||
* | ||
* @return array $options with all unknown options removed |
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.
$options
is superflu here
Yes, this looks great! |
Fix phpdoc as suggested by pborreli + add public method setUnknownOptionPolicy($unknownOptionPolicy) |
@iamluc you should fix your git username (vieilles instead of iamluc) https://help.github.com/articles/setting-your-username-in-git and fix with |
@pborreli thanks ! done. |
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 |
@stof OK, i will revert this. |
@iamluc move it back to the constructor IMO |
I would prefer if this functionality was configurable in the 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))) { |
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 need to set the third argument (strict) to true, otherwise '1'
would go throught but fail later
@bschussek PR updated. Is now BC because we changed Interface |
if ($flags & OptionsResolverInterface::REMOVE_UNKNOWN) { | ||
$options = $this->removeUnknownOptions($options); | ||
} | ||
elseif (!($flags & OptionsResolverInterface::IGNORE_UNKNOWN)) { |
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.
must be on the same line as the }
What is the status of this PR? @webmozart Can you check the latest version of the code? |
Replaced by #10574. |
Hi,
This commit adds the possibility to choose a policy on unknown options :