Ejemplo n.º 1
0
 public function preDeploy()
 {
     $siteArray = $this->site;
     if (empty($siteArray)) {
         throw new Exception('Site array could not be loaded');
     }
     $site = URLUtils::resolveSiteFromArray($siteArray, !empty($siteArray['matched_alias']) ? $siteArray['matched_alias'] : false);
     //
     //        $site = new Site();
     //        $site->Slug = $siteArray['slug'];
     //        $site->Name = isset($siteArray['name'])?$siteArray['name']:$site->Slug;
     //        $site->Description = isset($siteArray['description'])?$siteArray['description']:'';
     //
     //        if(isset($siteArray['domain']))
     //            $site->Domain = $siteArray['domain'];
     //        if(isset($siteArray['domain_base_uri']))
     //            $site->DomainBaseURI = $siteArray['domain_base_uri'];
     //        if(isset($siteArray['domain_aliases']))
     //            $site->DomainAliases = $siteArray['domain_aliases'];
     //        if(isset($siteArray['domain_redirects']))
     //            $site->DomainRedirects = $siteArray['domain_redirects'];
     //
     //        $site->BaseURL = 'http'.($site->isSSL()?'s':'').'://'.rtrim($domain.$site->DomainBaseURI,'/');
     $this->RequestContext->setSite($site);
     //        if(isset($siteArray['storagefacilities']))
     //        {
     //
     //            $sfs = $siteArray['storagefacilities'];
     //            foreach($sfs as $key => $sfArray)
     //            {
     //
     //                if(empty($sfArray['for']))
     //                    throw new Exception('storage_facility property "for" is missing');
     //
     //                if(empty($sfArray['ref']))
     //                    throw new Exception('storage_facility property "ref" is missing');
     //
     //                $info = new StorageFacilityInfo();
     //                $info->For = $sfArray['for'];
     //                $info->GenerateRewriteRules = isset($sfArray['generate_rewrite_rules'])?StringUtils::strToBool($sfArray['generate_rewrite_rules']):false;
     //                $info->ObjectRef = $sfArray['ref'];
     //
     //                $params = new StorageFacilityParams();
     //                $params->BaseURI = $sfArray['base_uri'];
     //                $params->BaseStoragePath = $sfArray['base_storage_path'];
     //                $params->Domain = $sfArray['domain'];
     //
     //                $info->StorageFacilityParams = $params;
     //
     //                $this->RequestContext->setStorageFacilityInfo($info->For, $info);
     //            }
     //        }
     foreach ($site->getStorageFacilityInfo() as $slug => $sf) {
         $this->RequestContext->setStorageFacilityInfo($slug, $sf);
     }
 }
Ejemplo n.º 2
0
 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;
     }
 }