private static function parse($path) { $path = trim($path); $libmodules = array(); if (file_exists($path)) { convertXmlObjToArr($xml = simplexml_load_file($path), $structure); } else { throw new Exception('[' . $path . '] cant be loaded'); } $i = 0; foreach ($structure[0]['@children'] as $children) { if (in_array($children['@name'], array('stylesheet', 'javascript'))) { self::$data[$children['@name']][] = $children['@attributes']; } else { if (in_array($children['@name'], array('layout'))) { self::$data[$children['@name']]['file'] = $children['@attributes']['file']; } else { if (in_array($children['@name'], array('role'))) { self::$data[$children['@name']]['need'] = $children['@attributes']['need']; } else { self::$data[$children['@name']] = $children['@text']; } } } } if (isset(self::$data['role']['need'])) { Error::CheckThrowAuth(self::$data['role']['need']); } // вынимаем модули $i = 0; $j = 0; foreach ($structure[1]['@children'] as $data) { $container = $data['@name']; foreach ($data['@children'] as $module) { $i++; $libmodules[$i] = $module['@attributes']; $libmodules[$i]['container'] = $container; if (isset($module['@children'])) { foreach ($module['@children'] as $param) { if ($param['@name'] == 'param') { $libmodules[$i]['params'][$j++] = $param['@attributes']; } } } } } //navigations if (isset($structure[2])) { /* @var $xml SimpleXMLElement */ $dom = new DOMDocument(); self::$navigations_string = $xml->navigations->asXML(); $dom->loadXML(self::$navigations_string); self::$navigations = $dom->getElementsByTagName('navigations')->item(0); } foreach ($libmodules as $module) { self::$modules[] = $module; } }
private static function parse($path) { $path = trim($path); $libmodules = array(); if (file_exists($path)) { convertXmlObjToArr(simplexml_load_file($path), $structure); } else { throw new Exception('[' . $path . '] cant be loaded'); } $i = 0; foreach ($structure[0]['@children'] as $children) { if (in_array($children['@name'], array('stylesheet', 'javascript'))) { self::$data[$children['@name']][] = $children['@attributes']; } else { if (in_array($children['@name'], array('layout'))) { self::$data[$children['@name']]['file'] = $children['@attributes']['file']; } else { if (in_array($children['@name'], array('role'))) { self::$data[$children['@name']]['need'] = $children['@attributes']['need']; } else { self::$data[$children['@name']] = $children['@text']; } } } } if (isset(self::$data['role']['need'])) { Error::CheckThrowAuth(self::$data['role']['need']); } // вынимаем модули $i = 0; $j = 0; foreach ($structure[1]['@children'] as $data) { $container = $data['@name']; foreach ($data['@children'] as $module) { $i++; $libmodules[$i] = $module['@attributes']; $libmodules[$i]['container'] = $container; if (isset($module['@children'])) { foreach ($module['@children'] as $param) { if ($param['@name'] == 'param') { $libmodules[$i]['params'][$j++] = $param['@attributes']; } } } } } foreach ($libmodules as $module) { self::$modules[] = $module; } }
function convertXmlObjToArr($obj, &$arr) { $children = $obj->children(); foreach ($children as $elementName => $node) { $nextIdx = count($arr); $arr[$nextIdx] = array(); $arr[$nextIdx]['@name'] = strtolower((string) $elementName); $arr[$nextIdx]['@attributes'] = array(); $attributes = $node->attributes(); foreach ($attributes as $attributeName => $attributeValue) { $attribName = strtolower(trim((string) $attributeName)); $attribVal = trim((string) $attributeValue); $arr[$nextIdx]['@attributes'][$attribName] = $attribVal; } $text = (string) $node; $text = trim($text); if (strlen($text) > 0) { $arr[$nextIdx]['@text'] = $text; } $arr[$nextIdx]['@children'] = array(); convertXmlObjToArr($node, $arr[$nextIdx]['@children']); } return; }