merged branch fabpot/serializer (PR #6302)
This PR was submitted for the master branch but it was merged into the 2.1 branch instead (closes #6302). Commits ------- d9b75a3 [Serializer] - Test undefined index # 1a3b985 Maintain array structure 0b9a831 Check if key # is defined in $value Discussion ---------- [Serializer] - undefined index # replaces #6293
This commit is contained in:
commit
e0cefd7f7e
@ -240,11 +240,15 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec
|
|||||||
|
|
||||||
if ($key === 'item') {
|
if ($key === 'item') {
|
||||||
if (isset($value['@key'])) {
|
if (isset($value['@key'])) {
|
||||||
$data[(string) $value['@key']] = $value['#'];
|
if (isset($value['#'])) {
|
||||||
|
$data[(string) $value['@key']] = $value['#'];
|
||||||
|
} else {
|
||||||
|
$data[(string) $value['@key']] = $value;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$data['item'][] = $value;
|
$data['item'][] = $value;
|
||||||
}
|
}
|
||||||
} elseif (array_key_exists($key, $data)) {
|
} elseif (array_key_exists($key, $data) || $key == "entry") {
|
||||||
if ((false === is_array($data[$key])) || (false === isset($data[$key][0]))) {
|
if ((false === is_array($data[$key])) || (false === isset($data[$key][0]))) {
|
||||||
$data[$key] = array($data[$key]);
|
$data[$key] = array($data[$key]);
|
||||||
}
|
}
|
||||||
|
@ -251,6 +251,39 @@ class XmlEncoderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($expected, $this->encoder->decode($source, 'xml'));
|
$this->assertEquals($expected, $this->encoder->decode($source, 'xml'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDecodeWithoutItemHash()
|
||||||
|
{
|
||||||
|
$obj = new ScalarDummy;
|
||||||
|
$obj->xmlFoo = array(
|
||||||
|
'foo-bar' => array(
|
||||||
|
'@key' => "value",
|
||||||
|
'item' => array("@key" => 'key', "key-val" => 'val')
|
||||||
|
),
|
||||||
|
'Foo' => array(
|
||||||
|
'Bar' => "Test",
|
||||||
|
'@Type' => 'test'
|
||||||
|
),
|
||||||
|
'föo_bär' => 'a',
|
||||||
|
"Bar" => array(1,2,3),
|
||||||
|
'a' => 'b',
|
||||||
|
);
|
||||||
|
$expected = array(
|
||||||
|
'foo-bar' => array(
|
||||||
|
'@key' => "value",
|
||||||
|
'key' => array('@key' => 'key', "key-val" => 'val')
|
||||||
|
),
|
||||||
|
'Foo' => array(
|
||||||
|
'Bar' => "Test",
|
||||||
|
'@Type' => 'test'
|
||||||
|
),
|
||||||
|
'föo_bär' => 'a',
|
||||||
|
"Bar" => array(1,2,3),
|
||||||
|
'a' => 'b',
|
||||||
|
);
|
||||||
|
$xml = $this->encoder->encode($obj, 'xml');
|
||||||
|
$this->assertEquals($expected, $this->encoder->decode($xml, 'xml'));
|
||||||
|
}
|
||||||
|
|
||||||
public function testPreventsComplexExternalEntities()
|
public function testPreventsComplexExternalEntities()
|
||||||
{
|
{
|
||||||
$oldCwd = getcwd();
|
$oldCwd = getcwd();
|
||||||
|
Reference in New Issue
Block a user