[Config] Unset key during normalization
This commit is contained in:
parent
46e3745a03
commit
e1402d495e
@ -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