Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 26f321c

Browse files
committed
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 ------- e1402d4 [Config] Unset key during normalization
2 parents 131a42b + e1402d4 commit 26f321c

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

src/Symfony/Component/Config/Definition/ArrayNode.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,10 @@ protected function normalizeValue($value)
288288
$normalized = array();
289289
foreach ($value as $name => $val) {
290290
if (isset($this->children[$name])) {
291-
$normalized[$name] = $this->children[$name]->normalize($val);
291+
try {
292+
$normalized[$name] = $this->children[$name]->normalize($val);
293+
} catch (UnsetKeyException $e) {
294+
}
292295
unset($value[$name]);
293296
} elseif (!$this->removeExtraKeys) {
294297
$normalized[$name] = $val;

src/Symfony/Component/Config/Definition/Builder/ExprBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public function thenEmptyArray()
149149
}
150150

151151
/**
152-
* Sets a closure marking the value as invalid at validation time.
152+
* Sets a closure marking the value as invalid at processing time.
153153
*
154154
* if you want to add the value of the node in your message just use a %s placeholder.
155155
*
@@ -167,7 +167,7 @@ public function thenInvalid($message)
167167
}
168168

169169
/**
170-
* Sets a closure unsetting this key of the array at validation time.
170+
* Sets a closure unsetting this key of the array at processing time.
171171
*
172172
* @return $this
173173
*

src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,25 @@ public function testNormalizeKeys()
231231
$this->assertFalse($this->getField($node, 'normalizeKeys'));
232232
}
233233

234+
public function testUnsetChild()
235+
{
236+
$node = new ArrayNodeDefinition('root');
237+
$node
238+
->children()
239+
->scalarNode('value')
240+
->beforeNormalization()
241+
->ifTrue(function ($value) {
242+
return empty($value);
243+
})
244+
->thenUnset()
245+
->end()
246+
->end()
247+
->end()
248+
;
249+
250+
$this->assertSame(array(), $node->getNode()->normalize(array('value' => null)));
251+
}
252+
234253
public function getEnableableNodeFixtures()
235254
{
236255
return array(

0 commit comments

Comments
 (0)