diff --git a/CHANGELOG-2.1.md b/CHANGELOG-2.1.md index 8bd7a1351d..974253e8c8 100644 --- a/CHANGELOG-2.1.md +++ b/CHANGELOG-2.1.md @@ -162,6 +162,33 @@ To get the diff between two versions, go to https://github.com/symfony/symfony/c * after login, the user is now redirected to `default_target_path` if `use_referer` is true and the referrer is the `login_path`. * added a way to remove a token from a session +### Serializer + + * [BC BREAK] convert the `item` XML tag to an array + + + + <![CDATA[title1]]><![CDATA[title2]]> + + + Before: + + Array() + + After: + + Array( + [item] => Array( + [0] => Array( + [title] => title1 + ) + [1] => Array( + [title] => title2 + ) + ) + ) + + ### Translation * added support for gettext diff --git a/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php b/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php index 1dec9fe71d..7fbde8e615 100644 --- a/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php +++ b/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php @@ -191,11 +191,8 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec if ($key === 'item') { if (isset($value['@key'])) { $data[(string) $value['@key']] = $value['#']; - } elseif (isset($data['item'])) { - $tmp = $data['item']; - unset($data['item']); - $data[] = $tmp; - $data[] = $value; + } else { + $data['item'][] = $value; } } elseif (array_key_exists($key, $data)) { if ((false === is_array($data[$key])) || (false === isset($data[$key][0]))) { diff --git a/tests/Symfony/Tests/Component/Serializer/Encoder/XmlEncoderTest.php b/tests/Symfony/Tests/Component/Serializer/Encoder/XmlEncoderTest.php index 22bff31a62..49d7a86142 100644 --- a/tests/Symfony/Tests/Component/Serializer/Encoder/XmlEncoderTest.php +++ b/tests/Symfony/Tests/Component/Serializer/Encoder/XmlEncoderTest.php @@ -239,6 +239,7 @@ class XmlEncoderTest extends \PHPUnit_Framework_TestCase ''. ''. ''. + '<![CDATA[title1]]><![CDATA[title2]]>'. ''. '1'. ''."\n"; @@ -249,7 +250,7 @@ class XmlEncoderTest extends \PHPUnit_Framework_TestCase $obj = new Dummy; $obj->foo = 'foo'; $obj->bar = array('a', 'b'); - $obj->baz = array('key' => 'val', 'key2' => 'val', 'A B' => 'bar', "Barry" => array('FooBar' => array("Baz"=>"Ed", "@id"=>1))); + $obj->baz = array('key' => 'val', 'key2' => 'val', 'A B' => 'bar', 'item' => array(array('title' => 'title1'), array('title' => 'title2')), 'Barry' => array('FooBar' => array('Baz' => 'Ed', '@id' => 1))); $obj->qux = "1"; return $obj;