-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[config] added remove option to ignoreExtraKeys #14238
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
Conversation
can you please link to the respective ticket? |
ok i know one that is related, i can do a PR perhaps on that inspired on this one |
Thanks. |
{ | ||
$this->ignoreExtraKeys = (bool) $boolean; | ||
$this->removeExtraKeys = $this->ignoreExtraKeys ? (bool) $remove : false; |
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.
can be simplyfied to $this->ignoreExtraKeys && $remove
@xabbuh Changes made |
The failed travis check doesn't seem to be related to my modifications. Is there anything I need to do here? |
I relaunched tests, they are green now. |
👍 on 2.8 |
👍 |
Thank you @twifty. |
…haviors (ogizanagi) This PR was merged into the 2.8 branch. Discussion ---------- [Config] Fix ArrayNode extra keys "ignore" and "remove" behaviors | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Due to #14238 , no more exception is thrown when submitting extra keys to an `ArrayNode`. For instance: ```php $builder = new TreeBuilder(); $nodeDefinition = $builder->root('root') ->children() ->scalarNode('foo') ->end() ->end(); $node = $nodeDefinition->getNode(true); $node->normalize(array( 'foo' => 'ok', 'bar' => 'ko', )); ``` will not throw a > Symfony\Component\Config\Definition\Exception\InvalidConfigurationException: Unrecognized option "bar" under "root"` anymore, as it does in 2.7. I think the expected behavior is: `Submitted data: ['bar' => 'ko']` Ignore | Remove | Expected | OK | Comment ---------| ------------ | ------------- | ------ | ---------- true | true | `[ ]` | ✔︎ | Previous behavior when ignoring. true | false | `['bar' => 'ko']` | ✔︎ | This is the result targeted by #14238. false | true | exception | ✘ | Removing makes no sense when not ignoring extra keys. <br/>The exception should still be thrown. false | false | exception | ✘ | Previous behavior (2.7). <br/>Should not have changed Commits ------- d961f7f [Config] Fix ArrayNode extra keys "ignore" and "remove" behaviors
I have added a remove option to the
ignoreExtraKeys()
method ofConfig/Definition/Builder/ArrayNodeDefinition
. The current implementation removes all such keys from the resulting array. This can at times be an inconvenience as we have to write extra methods to remove them before the validation then add them back again when done. Passing a boolean to the method now leaves them in place.