Commit ad306c96 authored by Ad Schellevis's avatar Ad Schellevis

minor cleanup in config handling, reduce xmlparse call overhead

parent 7953e21f
...@@ -98,43 +98,44 @@ class Config extends Singleton ...@@ -98,43 +98,44 @@ class Config extends Singleton
} }
foreach ($node->children() as $xmlNode) { foreach ($node->children() as $xmlNode) {
$xmlNodeName = $xmlNode->getName();
if ($xmlNode->count() > 0) { if ($xmlNode->count() > 0) {
$tmpNode = $this->toArray($forceList, $xmlNode); $tmpNode = $this->toArray($forceList, $xmlNode);
if (array_key_exists($xmlNode->getName(), $result)) { if (array_key_exists($xmlNodeName, $result)) {
$old_content = $result[$xmlNode->getName()]; $old_content = $result[$xmlNodeName];
// check if array content is associative, move items to new list // check if array content is associative, move items to new list
// (handles first item of specific type) // (handles first item of specific type)
if (!$this->isArraySequential($old_content)) { if (!$this->isArraySequential($old_content)) {
$result[$xmlNode->getName()] = array(); $result[$xmlNodeName] = array();
$result[$xmlNode->getName()][] = $old_content; $result[$xmlNodeName][] = $old_content;
} }
$result[$xmlNode->getName()][] = $tmpNode; $result[$xmlNodeName][] = $tmpNode;
} elseif (is_array($forceList) && array_key_exists($xmlNode->getName(), $forceList)) { } elseif (is_array($forceList) && array_key_exists($xmlNodeName, $forceList)) {
// force tag in an array // force tag in an array
$result[$xmlNode->getName()] = array(); $result[$xmlNodeName] = array();
$result[$xmlNode->getName()][] = $tmpNode; $result[$xmlNodeName][] = $tmpNode;
} else { } else {
$result[$xmlNode->getName()] = $tmpNode; $result[$xmlNodeName] = $tmpNode;
} }
} else { } else {
if (array_key_exists($xmlNode->getName(), $result)) { if (array_key_exists($xmlNodeName, $result)) {
// repeating item // repeating item
if (!is_array($result[$xmlNode->getName()])) { if (!is_array($result[$xmlNodeName])) {
// move first item into list // move first item into list
$tmp = $result[$xmlNode->getName()]; $tmp = $result[$xmlNodeName];
$result[$xmlNode->getName()] = array(); $result[$xmlNodeName] = array();
$result[$xmlNode->getName()][] = $tmp; $result[$xmlNodeName][] = $tmp;
} }
$result[$xmlNode->getName()][] = $xmlNode->__toString(); $result[$xmlNodeName][] = $xmlNode->__toString();
} else { } else {
// single content item // single content item
if (is_array($forceList) && array_key_exists($xmlNode->getName(), $forceList)) { if (is_array($forceList) && array_key_exists($xmlNodeName, $forceList)) {
$result[$xmlNode->getName()] = array(); $result[$xmlNodeName] = array();
if ($xmlNode->__toString() != null && trim($xmlNode->__toString()) !== "") { if ($xmlNode->__toString() != null && trim($xmlNode->__toString()) !== "") {
$result[$xmlNode->getName()][] = $xmlNode->__toString(); $result[$xmlNodeName][] = $xmlNode->__toString();
} }
} else { } else {
$result[$xmlNode->getName()] = $xmlNode->__toString(); $result[$xmlNodeName] = $xmlNode->__toString();
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment