bug #29152 [Config] Unset key during normalization (ro0NL)
This PR was squashed before being merged into the 2.8 branch (closes #29152).
Discussion
----------
[Config] Unset key during normalization
| Q | A
| ------------- | ---
| Branch? | 2.8
| Bug fix? | yes-ish
| New feature? | yes
| BC breaks? | no <!-- see https://symfony.com/bc -->
| Deprecations? | no
| Tests pass? | yes <!-- please add some, will be required by reviewers -->
| Fixed tickets | #29142
| License | MIT
| Doc PR | symfony/symfony-docs#... <!-- required for new features -->
2.8 vs. 4.x :) let me know.
Commits
-------
e1402d495e
[Config] Unset key during normalization
This commit is contained in:
commit
26f321cb01
@ -288,7 +288,10 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface
|
||||
$normalized = array();
|
||||
foreach ($value as $name => $val) {
|
||||
if (isset($this->children[$name])) {
|
||||
try {
|
||||
$normalized[$name] = $this->children[$name]->normalize($val);
|
||||
} catch (UnsetKeyException $e) {
|
||||
}
|
||||
unset($value[$name]);
|
||||
} elseif (!$this->removeExtraKeys) {
|
||||
$normalized[$name] = $val;
|
||||
|
@ -149,7 +149,7 @@ class ExprBuilder
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a closure marking the value as invalid at validation time.
|
||||
* Sets a closure marking the value as invalid at processing time.
|
||||
*
|
||||
* if you want to add the value of the node in your message just use a %s placeholder.
|
||||
*
|
||||
@ -167,7 +167,7 @@ class ExprBuilder
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a closure unsetting this key of the array at validation time.
|
||||
* Sets a closure unsetting this key of the array at processing time.
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
|
@ -231,6 +231,25 @@ class ArrayNodeDefinitionTest extends TestCase
|
||||
$this->assertFalse($this->getField($node, 'normalizeKeys'));
|
||||
}
|
||||
|
||||
public function testUnsetChild()
|
||||
{
|
||||
$node = new ArrayNodeDefinition('root');
|
||||
$node
|
||||
->children()
|
||||
->scalarNode('value')
|
||||
->beforeNormalization()
|
||||
->ifTrue(function ($value) {
|
||||
return empty($value);
|
||||
})
|
||||
->thenUnset()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
;
|
||||
|
||||
$this->assertSame(array(), $node->getNode()->normalize(array('value' => null)));
|
||||
}
|
||||
|
||||
public function getEnableableNodeFixtures()
|
||||
{
|
||||
return array(
|
||||
|
Reference in New Issue
Block a user