Skip to content

[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

Closed
wants to merge 1 commit into from
Closed

[config] added remove option to ignoreExtraKeys #14238

wants to merge 1 commit into from

Conversation

twifty
Copy link

@twifty twifty commented Apr 6, 2015

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR

I have added a remove option to the ignoreExtraKeys() method of Config/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.

@cordoval
Copy link
Contributor

cordoval commented Apr 6, 2015

can you please link to the respective ticket?

@twifty
Copy link
Author

twifty commented Apr 6, 2015

@cordoval There isn't a ticket but I did mention the feature in #13957

@cordoval
Copy link
Contributor

cordoval commented Apr 6, 2015

ok i know one that is related, i can do a PR perhaps on that inspired on this one

@twifty
Copy link
Author

twifty commented Apr 6, 2015

Thanks.

{
$this->ignoreExtraKeys = (bool) $boolean;
$this->removeExtraKeys = $this->ignoreExtraKeys ? (bool) $remove : false;
Copy link
Member

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

@twifty
Copy link
Author

twifty commented Apr 7, 2015

@xabbuh Changes made

@twifty
Copy link
Author

twifty commented Apr 7, 2015

The failed travis check doesn't seem to be related to my modifications. Is there anything I need to do here?

@nicolas-grekas
Copy link
Member

I relaunched tests, they are green now.

@nicolas-grekas
Copy link
Member

👍 on 2.8

@xabbuh
Copy link
Member

xabbuh commented Jun 22, 2015

👍

@xabbuh
Copy link
Member

xabbuh commented Jun 28, 2015

ping @fabpot @stof

@fabpot
Copy link
Member

fabpot commented Jun 28, 2015

Thank you @twifty.

@fabpot fabpot closed this in 674b124 Jun 28, 2015
fabpot added a commit that referenced this pull request Sep 30, 2015
…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
@fabpot fabpot mentioned this pull request Nov 16, 2015
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.

5 participants