From a0561e5dde3429f66b8475231af063715d1a5d29 Mon Sep 17 00:00:00 2001 From: excelwebzone Date: Wed, 23 Nov 2011 17:40:26 -0800 Subject: [PATCH 1/3] Replaced `item` with `*item` when parsing XML string --- CHANGELOG-2.1.md | 4 ++++ src/Symfony/Component/Serializer/Encoder/XmlEncoder.php | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG-2.1.md b/CHANGELOG-2.1.md index 9d38d81f1c..77823eaf9e 100644 --- a/CHANGELOG-2.1.md +++ b/CHANGELOG-2.1.md @@ -159,6 +159,10 @@ 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] replaced the `item` XML tag with `*item` + ### 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..9ca8c59091 100644 --- a/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php +++ b/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php @@ -188,12 +188,12 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec $value = (string) $subnode; } - if ($key === 'item') { + if ($key === '*item') { if (isset($value['@key'])) { $data[(string) $value['@key']] = $value['#']; - } elseif (isset($data['item'])) { - $tmp = $data['item']; - unset($data['item']); + } elseif (isset($data['*item'])) { + $tmp = $data['*item']; + unset($data['*item']); $data[] = $tmp; $data[] = $value; } From c9a2b49eb7d890171c7b23fb3384f619000516e6 Mon Sep 17 00:00:00 2001 From: excelwebzone Date: Thu, 24 Nov 2011 09:09:38 -0800 Subject: [PATCH 2/3] Fixed xml encoder test script, and group `item` tags into an array --- src/Symfony/Component/Serializer/Encoder/XmlEncoder.php | 9 +++------ .../Component/Serializer/Encoder/XmlEncoderTest.php | 3 ++- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php b/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php index 9ca8c59091..7fbde8e615 100644 --- a/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php +++ b/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php @@ -188,14 +188,11 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec $value = (string) $subnode; } - if ($key === '*item') { + 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; From 8710a132ea64693900efce1c2881babf90658709 Mon Sep 17 00:00:00 2001 From: excelwebzone Date: Fri, 25 Nov 2011 00:46:40 -0800 Subject: [PATCH 3/3] Added example to the change log file --- CHANGELOG-2.1.md | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/CHANGELOG-2.1.md b/CHANGELOG-2.1.md index 77823eaf9e..158cb36e6f 100644 --- a/CHANGELOG-2.1.md +++ b/CHANGELOG-2.1.md @@ -161,7 +161,30 @@ To get the diff between two versions, go to https://github.com/symfony/symfony/c ### Serializer - * [BC BREAK] replaced the `item` XML tag with `*item` + * [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