Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[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
[Config] Unset key during normalization
  • Loading branch information
ro0NL authored and fabpot committed Nov 12, 2018
commit e1402d495e70c0e03f28bce186fe946a31d81e31
5 changes: 4 additions & 1 deletion 5 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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.