8000 [Config] Unset key during normalization by ro0NL · Pull Request #29152 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Config] Unset key during normalization #29152

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

Merged
merged 1 commit into from
Nov 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Symfony/Component/Config/Definition/ArrayNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,10 @@ protected function normalizeValue($value)
$normalized = array();
foreach ($value as $name => $val) {
if (isset($this->children[$name])) {
$normalized[$name] = $this->children[$name]->normalize($val);
try {
$normalized[$name] = $this->children[$name]->normalize($val);
} catch (UnsetKeyException $e) {
}
unset($value[$name]);
} elseif (!$this->removeExtraKeys) {
$normalized[$name] = $val;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public function thenEmptyArray()
}

/**
* 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.
*
Expand All @@ -167,7 +167,7 @@ public function thenInvalid($message)
}

/**
* 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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,25 @@ public function testNormalizeKeys()
$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(
Expand Down
0