Commit 46d28496 authored by Ad Schellevis's avatar Ad Schellevis

update fromArray to support forced lists on specific tags

parent da2c3c1b
...@@ -72,11 +72,12 @@ class Config extends Singleton ...@@ -72,11 +72,12 @@ class Config extends Singleton
/** /**
* serialize xml to array structure (backwards compatibility mode) * serialize xml to array structure (backwards compatibility mode)
* @param null|array $forceList force specific tags to be contained in a list.
* @param DOMNode $node * @param DOMNode $node
* @return string|array * @return string|array
* @throws ConfigException * @throws ConfigException
*/ */
public function toArray($node = null) public function toArray($forceList = null, $node = null)
{ {
$result = array(); $result = array();
$this->checkvalid(); $this->checkvalid();
...@@ -87,11 +88,12 @@ class Config extends Singleton ...@@ -87,11 +88,12 @@ class Config extends Singleton
foreach ($node->children() as $xmlNode) { foreach ($node->children() as $xmlNode) {
if ($xmlNode->count() > 0) { if ($xmlNode->count() > 0) {
$tmpNode = $this->toArray($xmlNode); $tmpNode = $this->toArray($forceList, $xmlNode);
if (array_key_exists($xmlNode->getName(), $result)) { if (array_key_exists($xmlNode->getName(), $result)) {
$old_content = $result[$xmlNode->getName()]; $old_content = $result[$xmlNode->getName()];
// check if array content is associative, if move items to list // check if array content is associative, if move items to list
if (array_keys($old_content) !== range(0, count($old_content) - 1)) { if (array_keys($old_content) !== range(0, count($old_content) - 1) ||
array_key_exists($xmlNode->getName(), $forceList)) {
$result[$xmlNode->getName()] = array(); $result[$xmlNode->getName()] = array();
$result[$xmlNode->getName()][] = $old_content; $result[$xmlNode->getName()][] = $old_content;
} }
...@@ -111,10 +113,15 @@ class Config extends Singleton ...@@ -111,10 +113,15 @@ class Config extends Singleton
$result[$xmlNode->getName()][] = $xmlNode->__toString(); $result[$xmlNode->getName()][] = $xmlNode->__toString();
} else { } else {
// single content item // single content item
if (array_key_exists($xmlNode->getName(), $forceList)) {
$result[$xmlNode->getName()] = array();
$result[$xmlNode->getName()][] = $xmlNode->__toString();
} else {
$result[$xmlNode->getName()] = $xmlNode->__toString(); $result[$xmlNode->getName()] = $xmlNode->__toString();
} }
} }
} }
}
return $result; return $result;
} }
...@@ -337,7 +344,7 @@ class Config extends Singleton ...@@ -337,7 +344,7 @@ class Config extends Singleton
// try to read backup info from xml // try to read backup info from xml
$xmlNode = simplexml_load_file($filename, "SimpleXMLElement", LIBXML_NOERROR | LIBXML_ERR_NONE); $xmlNode = simplexml_load_file($filename, "SimpleXMLElement", LIBXML_NOERROR | LIBXML_ERR_NONE);
if (isset($xmlNode->revision)) { if (isset($xmlNode->revision)) {
$result[$filename] = $this->toArray($xmlNode->revision); $result[$filename] = $this->toArray(null, $xmlNode->revision);
} }
} }
......
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