protected function parse() { if ($this->changed) { return; } if ($this->parsed != true) { $this->cmsNavItems = array(); $this->plugins = array(); $this->aspects = array(); $this->elements = array(); $this->site = null; $xml = $this->SimpleXMLParser->parseXMLFile($this->environmentsXMLFile); foreach ($xml as $ename => $enode) { switch ((string) $ename) { case 'environment': foreach ($enode->attributes() as $name => $value) { $environment[$name] = (string) $value; } if (!empty($environment['slug']) && strtolower($environment['slug']) != strtolower($_SERVER['ENVIRONMENT'])) { continue; } $this->rewriteBase = strval($enode->rewrite_base); $this->publicFilesBaseURI = strval($enode->public_files_base_uri); foreach ($enode as $name => $node) { switch ((string) $name) { case 'context': $context = array('sites' => array()); foreach ($node->attributes() as $name => $value) { $context[$name] = (string) $value; } foreach ($node as $childNode) { if ($childNode->getName() == 'sites') { foreach ($childNode as $siteNode) { $site = array(); foreach ($siteNode->attributes() as $name => $value) { $site[$name] = (string) $value; } // By default if a site is not specified as enabled, it is enabled. if (!array_key_exists('enabled', $site)) { $site['enabled'] = true; } // If the context that contains the site is disabled // The site within it should always be disabled. if (!StringUtils::strToBool($context['enabled'])) { $site['enabled'] = false; } foreach ($siteNode as $siteChildNode) { if ((string) $siteChildNode->getName() == 'storage_facility') { $sf = array(); foreach ($siteChildNode->attributes() as $name => $value) { $sf[$name] = (string) $value; } foreach ($siteChildNode as $sfChildNode) { $sf[(string) $sfChildNode->getName()] = (string) $sfChildNode; } if (isset($sf['for'])) { $site['storagefacilities'][$sf['for']] = $sf; } } else { $site[(string) $siteChildNode->getName()] = (string) $siteChildNode; } } $this->siteContext = $context; $this->site = $site; break; } } else { if ($childNode->getName() == 'storage_facility') { $sf = array(); foreach ($childNode->attributes() as $name => $value) { $sf[$name] = (string) $value; } foreach ($childNode as $sfChildNode) { $sf[(string) $sfChildNode->getName()] = (string) $sfChildNode; } if (isset($sf['for'])) { $context['storagefacilities'][$sf['for']] = $sf; } } else { $context[(string) $childNode->getName()] = (string) $childNode; } } } if (empty($context['sites'])) { unset($context['sites']); } $contextObject = URLUtils::resolveContextFromArray($context, $this->isAliasDomain); $contextObject->ContextID = count($this->contexts) + 1; $this->contexts[] = $contextObject; break; } } break; } } $xml = $this->SimpleXMLParser->parseXMLFile($this->systemXMLFile); foreach ($xml as $name => $node) { $array = array(); $sort_array = array(); $sort_array2 = array(); switch ((string) $name) { case 'plugins': foreach ($node as $pluginNode) { if ($pluginNode->getName() == 'plugin') { $item = $this->SystemXMLConverter->xmlToPlugin(new Plugin(), $pluginNode); $sort_array[] = $item->Slug; $array[] = $item; } } array_multisort($sort_array, SORT_ASC, $array); $this->plugins = $array; break; case 'elements': foreach ($node as $elementNode) { if ($elementNode->getName() == 'element') { $item = $this->SystemXMLConverter->xmlToElement(new Element(), $elementNode); $sort_array[] = $item->Slug; $array[] = $item; } } array_multisort($sort_array, SORT_ASC, $array); $this->elements = $array; break; case 'aspects': foreach ($node as $aspectNode) { if ($aspectNode->getName() == 'aspect') { $item = $this->SystemXMLConverter->xmlToAspect(new Aspect(), $aspectNode); $sort_array[] = $item->Slug; $array[] = $item; } } array_multisort($sort_array, SORT_ASC, $array); $this->aspects = $array; break; case 'cmsnavitems': foreach ($node as $cmsNavNode) { if ($cmsNavNode->getName() == 'item') { $item = $this->SystemXMLConverter->xmlToCMSNavItem(new CMSNavItem(), $cmsNavNode); $sort_array[] = $item->SortOrder; $sort_array2[] = $item->Slug; $array[] = $item; } } array_multisort($sort_array, SORT_ASC, $sort_array2, SORT_ASC, $array); $this->cmsNavItems = $array; break; } } $contextArray = $this->siteContext; $site2 = array_merge($contextArray, $this->site); if (isset($contextArray['storagefacilities'])) { foreach ($contextArray['storagefacilities'] as $key => $sf) { $site2['storagefacilities'][$key] = $sf; } } if (isset($site['storagefacilities'])) { foreach ($site['storagefacilities'] as $key => $sf) { $site2['storagefacilities'][$key] = $sf; } } $site2['context'] = $contextArray['slug']; unset($site2['sites']); $siteArray = $site2; $site = URLUtils::resolveSiteFromArray($siteArray, $this->isAliasDomain); $site->SiteID = 1; $this->sites[$site->Slug] = $site; $this->parsed = true; } }