/** * converts php-structure to DOM-object. * * @param array $arr php-structure * @param SimpleXMLElement $node parent node where new element to attach * @param DOMDocument $dom DOMDocument object * @return SimpleXMLElement */ public static function convertPhpObjToDom($arr, $node, $dom) { if (is_array($arr)) { /** * If arr has integer keys, this php-array must be converted in * xml-array representation (<array><item>..</item>..</array>) */ $arrayParam = array(); foreach ($arr as $k => $v) { if (is_integer($k)) { $arrayParam[] = $v; } } if (0 < count($arrayParam)) { $node->appendChild($arrayDom = $dom->createElement("array")); foreach ($arrayParam as $key => $val) { $new = $arrayDom->appendChild($dom->createElement('item')); self::convertPhpObjToDom($val, $new, $dom); } } else { foreach ($arr as $key => $val) { $new = $node->appendChild($dom->createElement(self::encode($key))); self::convertPhpObjToDom($val, $new, $dom); } } } else { $node->appendChild($dom->createTextNode(self::encode($arr))); } }
protected function _convertLayoutHeadNode(SimpleXMLElement $sourceXml, SimpleXMLElement $targetXml) { foreach ($sourceXml->children() as $child) { $path = $this->_env['ext_name'] . '::' . (string) $child; break; } switch ((string) $sourceXml['method']) { case 'addJs': $targetNode = $targetXml->addChild('js'); $targetNode->addAttribute('class', $path); break; case 'addCss': $targetNode = $targetXml->addChild('css'); $targetNode->addAttribute('src', $path); break; default: $targetNode = $targetXml->appendChild($sourceXml->cloneNode(true)); } }