diff --git a/src/Symfony/Component/Config/Definition/ArrayNode.php b/src/Symfony/Component/Config/Definition/ArrayNode.php index 457e7a8c92e34..52b191200fd74 100644 --- a/src/Symfony/Component/Config/Definition/ArrayNode.php +++ b/src/Symfony/Component/Config/Definition/ArrayNode.php @@ -52,10 +52,14 @@ public function setNormalizeKeys($normalizeKeys) */ protected function preNormalize($value) { - if (!$this->normalizeKeys || !is_array($value)) { + if (!is_array($value)) { return $value; } + if (!$this->normalizeKeys) { + return $this->remapXml($value); + } + $normalized = array(); foreach ($value as $k => $v) { @@ -66,7 +70,7 @@ protected function preNormalize($value) } } - return $normalized; + return $this->remapXml($normalized); } /** @@ -299,8 +303,6 @@ protected function normalizeValue($value) return $value; } - $value = $this->remapXml($value); - $normalized = array(); foreach ($value as $name => $val) { if (isset($this->children[$name])) { diff --git a/src/Symfony/Component/Config/Definition/PrototypedArrayNode.php b/src/Symfony/Component/Config/Definition/PrototypedArrayNode.php index 1c3c2188326be..3ff1382179e8d 100644 --- a/src/Symfony/Component/Config/Definition/PrototypedArrayNode.php +++ b/src/Symfony/Component/Config/Definition/PrototypedArrayNode.php @@ -233,8 +233,6 @@ protected function normalizeValue($value) return $value; } - $value = $this->remapXml($value); - $isAssoc = array_keys($value) !== range(0, count($value) - 1); $normalized = array(); foreach ($value as $k => $v) { diff --git a/src/Symfony/Component/Config/Tests/Definition/ArrayNodeTest.php b/src/Symfony/Component/Config/Tests/Definition/ArrayNodeTest.php index 8373ad930277b..7a3d015ac2e85 100644 --- a/src/Symfony/Component/Config/Tests/Definition/ArrayNodeTest.php +++ b/src/Symfony/Component/Config/Tests/Definition/ArrayNodeTest.php @@ -13,6 +13,7 @@ use Symfony\Component\Config\Definition\ArrayNode; use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; +use Symfony\Component\Config\Definition\PrototypedArrayNode; use Symfony\Component\Config\Definition\ScalarNode; class ArrayNodeTest extends \PHPUnit_Framework_TestCase @@ -68,11 +69,33 @@ public function testIgnoreAndRemoveBehaviors($ignore, $remove, $expected, $messa public function testPreNormalize($denormalized, $normalized) { $node = new ArrayNode('foo'); + $node->addChild(new ScalarNode('foo_bar')); + $node->addChild(new ScalarNode('foo-bar')); + $node->addChild(new ScalarNode('foo-bar_moo')); + $node->addChild(new ScalarNode('anything_with_dash_and_no_underscore')); + $node->addChild(new ScalarNode('no_dash')); - $r = new \ReflectionMethod($node, 'preNormalize'); - $r->setAccessible(true); + $prototypeNode = new ArrayNode('subfoo'); + $prototypeNode->addChild(new ScalarNode('bar')); + $prototype = new PrototypedArrayNode('plural'); + $prototype->setPrototype($prototypeNode); + $prototype->setKeyAttribute('x'); + + $node->setXmlRemappings(array( + array('singular', 'plural'), + )); + $node->addChild($prototype); + + $node->setNormalizationClosures(array( + function ($v) use ($normalized) { + $this->assertSame($normalized, $v); + + return $v; + }, + )); + + $this->assertSame($normalized, $node->normalize($denormalized)); - $this->assertSame($normalized, $r->invoke($node, $denormalized)); } public function getPreNormalizationTests() @@ -94,6 +117,10 @@ public function getPreNormalizationTests() array('foo-bar' => null, 'foo_bar' => 'foo'), array('foo-bar' => null, 'foo_bar' => 'foo'), ), + array( + array('singular' => array(array('x' => 'foo', 'bar' => 'foo'), array('x' => 'bar', 'bar' => 'bar'))), + array('plural' => array('foo' => array('bar' => 'foo'), 'bar' => array('bar' => 'bar'))), + ) ); }