protected function _addBranch(\Zend_Config $config, \SimpleXMLElement $xml, \SimpleXMLElement $parent)
{
$branchType = null;
foreach ($config as $key => $value) {
$attributes = null;
if ($value instanceof \Zend_Config) {
$attributes = $value->get('@attributes');
if ($attributes || $value->get('@value')) {
$value = $value->get('@value');
}
}
if ($branchType === null) {
if (is_numeric($key)) {
$branchType = 'numeric';
$branchName = $xml->getName();
$xml = $parent;
unset($parent->{$branchName});
} else {
$branchType = 'string';
}
} elseif ($branchType !== (is_numeric($key) ? 'numeric' : 'string')) {
// require_once 'Zend/Config/Exception.php';
throw new \Zend_Config_Exception('Mixing of string and numeric keys is not allowed');
}
if ($branchType === 'numeric') {
if ($value instanceof \Zend_Config) {
$child = $this->applyAttributes($parent->addChild($branchName), $attributes);
$this->_addBranch($value, $child, $parent);
} else {
$child = $this->applyAttributes($parent->addChild($branchName, (string) $value), $attributes);
}
} else {
if ($value instanceof \Zend_Config) {
$child = $xml->addChild($key);
$this->applyAttributes($child, $attributes);
$this->_addBranch($value, $child, $xml);
} else {
$this->addChildConsiderCdata($xml, $key, $value);
}
}
}
}