Skip to content

Commit d6f01df

Browse files
committed
merged branch excelwebzone/dev (PR #2706)
Commits ------- 8710a13 Added example to the change log file c9a2b49 Fixed xml encoder test script, and group `item` tags into an array a0561e5 Replaced `item` with `*item` when parsing XML string Discussion ---------- Replaced `item` with `*item` when parsing XML string --------------------------------------------------------------------------- by fabpot at 2011/11/23 22:14:12 -0800 Tests do not pass: 1) Symfony\Tests\Component\Serializer\Encoder\XmlEncoderTest::testDecode Failed asserting that two arrays are equal. --- Expected +++ Actual @@ @@ 'key2' => 'val' - 'A B' => 'bar' 'Barry' => Array (...) + 'item' => Array (...) ) 'qux' => '1' ) .../tests/Symfony/Tests/Component/Serializer/Encoder/XmlEncoderTest.php:173 --------------------------------------------------------------------------- by fabpot at 2011/11/24 22:57:37 -0800 I don't understand the patch anymore. I don't see any use of `*item` in the code. --------------------------------------------------------------------------- by excelwebzone at 2011/11/24 23:04:07 -0800 I run some testing and you can't use '*item' XML parser reject it. So I modified it to convert it to an array.. Look at the test script change --------------------------------------------------------------------------- by fabpot at 2011/11/24 23:13:30 -0800 So, you probably need to change the CHANGELOG as well? You should add an example which shows a before/after example. --------------------------------------------------------------------------- by excelwebzone at 2011/11/24 23:15:51 -0800 Yes, forgot to change that.. --------------------------------------------------------------------------- by fabpot at 2011/11/25 01:27:42 -0800 ping @Seldaek, @lsmith77 --------------------------------------------------------------------------- by Seldaek at 2011/11/25 04:16:43 -0800 There are other meta-names available in the XmlEncoder, @-something for attributes, then there is something happening with a # but I'm not quite sure what. I'm just saying, maybe *item isn't the best name, if it introduces a third metacharacter. Apart from that I'm fine with it. --------------------------------------------------------------------------- by excelwebzone at 2011/11/25 08:45:31 -0800 Maybe we can rename it to `wildcard` instead --------------------------------------------------------------------------- by excelwebzone at 2011/11/25 15:12:09 -0800 Any chance we can push this throw? --------------------------------------------------------------------------- by lsmith77 at 2011/11/27 04:06:25 -0800 here is the old PR #2682 @Seldaek: i think your comment was made for an older version of the patch. overall I am fine with the change, the Serializer component takes a fairly simple approach. it is also not designed to really produce XML or JSON cleanly from the same data. it will really only be able to output a clean API for one or the other with the same data structure. --------------------------------------------------------------------------- by excelwebzone at 2011/12/01 06:25:24 -0800 @fabpot can we merge this change
2 parents 342def5 + 8710a13 commit d6f01df

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

CHANGELOG-2.1.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,33 @@ To get the diff between two versions, go to https://github.com/symfony/symfony/c
162162
* after login, the user is now redirected to `default_target_path` if `use_referer` is true and the referrer is the `login_path`.
163163
* added a way to remove a token from a session
164164

165+
### Serializer
166+
167+
* [BC BREAK] convert the `item` XML tag to an array
168+
169+
<?xml version="1.0"?>
170+
<response>
171+
<item><title><![CDATA[title1]]></title></item><item><title><![CDATA[title2]]></title></item>
172+
</response>
173+
174+
Before:
175+
176+
Array()
177+
178+
After:
179+
180+
Array(
181+
[item] => Array(
182+
[0] => Array(
183+
[title] => title1
184+
)
185+
[1] => Array(
186+
[title] => title2
187+
)
188+
)
189+
)
190+
191+
165192
### Translation
166193

167194
* added support for gettext

src/Symfony/Component/Serializer/Encoder/XmlEncoder.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,8 @@ private function parseXml($node)
191191
if ($key === 'item') {
192192
if (isset($value['@key'])) {
193193
$data[(string) $value['@key']] = $value['#'];
194-
} elseif (isset($data['item'])) {
195-
$tmp = $data['item'];
196-
unset($data['item']);
197-
$data[] = $tmp;
198-
$data[] = $value;
194+
} else {
195+
$data['item'][] = $value;
199196
}
200197
} elseif (array_key_exists($key, $data)) {
201198
if ((false === is_array($data[$key])) || (false === isset($data[$key][0]))) {

tests/Symfony/Tests/Component/Serializer/Encoder/XmlEncoderTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ protected function getXmlSource()
239239
'<foo><![CDATA[foo]]></foo>'.
240240
'<bar><![CDATA[a]]></bar><bar><![CDATA[b]]></bar>'.
241241
'<baz><key><![CDATA[val]]></key><key2><![CDATA[val]]></key2><item key="A B"><![CDATA[bar]]></item>'.
242+
'<item><title><![CDATA[title1]]></title></item><item><title><![CDATA[title2]]></title></item>'.
242243
'<Barry><FooBar id="1"><Baz><![CDATA[Ed]]></Baz></FooBar></Barry></baz>'.
243244
'<qux>1</qux>'.
244245
'</response>'."\n";
@@ -249,7 +250,7 @@ protected function getObject()
249250
$obj = new Dummy;
250251
$obj->foo = 'foo';
251252
$obj->bar = array('a', 'b');
252-
$obj->baz = array('key' => 'val', 'key2' => 'val', 'A B' => 'bar', "Barry" => array('FooBar' => array("Baz"=>"Ed", "@id"=>1)));
253+
$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)));
253254
$obj->qux = "1";
254255

255256
return $obj;

0 commit comments

Comments
 (0)