mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 11:06:15 +00:00
Fixing Xml::toArray() when blank nodes are provided. Fixes #87.
This commit is contained in:
parent
06fb86f141
commit
7116c01642
2 changed files with 25 additions and 4 deletions
|
@ -672,7 +672,6 @@ class XmlNode extends Object {
|
||||||
continue;
|
continue;
|
||||||
} elseif (isset($child->children[0]) && is_a($child->children[0], 'XmlTextNode')) {
|
} elseif (isset($child->children[0]) && is_a($child->children[0], 'XmlTextNode')) {
|
||||||
$value = $child->children[0]->value;
|
$value = $child->children[0]->value;
|
||||||
|
|
||||||
if ($child->attributes) {
|
if ($child->attributes) {
|
||||||
$value = array_merge(array('value' => $value), $child->attributes);
|
$value = array_merge(array('value' => $value), $child->attributes);
|
||||||
}
|
}
|
||||||
|
@ -688,10 +687,10 @@ class XmlNode extends Object {
|
||||||
continue;
|
continue;
|
||||||
} elseif (count($child->children) === 0 && $child->value == '') {
|
} elseif (count($child->children) === 0 && $child->value == '') {
|
||||||
$value = $child->attributes;
|
$value = $child->attributes;
|
||||||
if (isset($out[$child->name]) || isset($multi[$key])) {
|
if (isset($out[$key]) || isset($multi[$key])) {
|
||||||
if (!isset($multi[$key])) {
|
if (!isset($multi[$key])) {
|
||||||
$multi[$key] = array($out[$child->name]);
|
$multi[$key] = array($out[$key]);
|
||||||
unset($out[$child->name]);
|
unset($out[$key]);
|
||||||
}
|
}
|
||||||
$multi[$key][] = $value;
|
$multi[$key][] = $value;
|
||||||
} elseif (!empty($value)) {
|
} elseif (!empty($value)) {
|
||||||
|
|
|
@ -1188,7 +1188,29 @@ class XmlTest extends CakeTestCase {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
|
$text = '<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<root>
|
||||||
|
<child id="1" other="1" />
|
||||||
|
<child id="2" other="1" />
|
||||||
|
<child id="3" other="1" />
|
||||||
|
<child id="4" other="1" />
|
||||||
|
<child id="5" other="1" />
|
||||||
|
</root>';
|
||||||
|
$xml = new Xml($text);
|
||||||
|
$result = $xml->toArray();
|
||||||
|
$expected = array(
|
||||||
|
'Root' => array(
|
||||||
|
'Child' => array(
|
||||||
|
array('id' => 1, 'other' => 1),
|
||||||
|
array('id' => 2, 'other' => 1),
|
||||||
|
array('id' => 3, 'other' => 1),
|
||||||
|
array('id' => 4, 'other' => 1),
|
||||||
|
array('id' => 5, 'other' => 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue