示例#1
0
 protected function instantiateTemplate()
 {
     $tpname = $this->_disp->Get(DInfo::FLD_ViewName);
     $vhname = $this->_disp->GetLast(DInfo::FLD_REF);
     $s_tpnode = $this->_serv->GetChildNodeById('vhTemplate', $tpname);
     if ($s_tpnode == NULL) {
         return false;
     }
     $s_vhnode = $s_tpnode->GetChildNodeById('member', $vhname);
     if ($s_vhnode == NULL) {
         return false;
     }
     $confpath = $this->getConfFilePath(DInfo::CT_TP, $tpname);
     $tp = new CData(DInfo::CT_TP, $confpath);
     if (($conferr = $tp->GetConfErr()) != NULL) {
         $this->_disp->Set(DInfo::FLD_TopMsg, $conferr);
         return false;
     }
     $tproot = $tp->GetRootNode();
     $configfile = $tproot->GetChildVal('configFile');
     if ($configfile == NULL) {
         return false;
     }
     $vhRoot_path = '';
     if (strncasecmp('$VH_ROOT', $configfile, 8) == 0) {
         $vhRoot_path = $s_vhnode->GetChildVal('vhRoot');
         // customized
         if ($vhRoot_path == NULL) {
             //default
             $vhRoot_path = $tproot->GetChildVal('vhRoot');
             if ($vhRoot_path == NULL) {
                 return false;
             }
         }
     }
     $configfile = PathTool::GetAbsFile($configfile, 'VR', $vhname, $vhRoot_path);
     $vh = new CData(DInfo::CT_VH, $configfile, "`{$vhname}");
     if (($conferr = $vh->GetConfErr()) != NULL) {
         $this->_disp->Set(DInfo::FLD_TopMsg, $conferr);
         return false;
     }
     $vhroot = $tproot->GetChildren('virtualHostConfig');
     if ($vhroot == false) {
         return false;
     }
     $vh->SetRootNode($vhroot);
     $vh->SaveFile();
     // save serv file
     $basemap = new DTblMap(array('', '*virtualhost$name'), 'V_TOPD');
     $tproot->AddChild(new CNode('name', $vhname));
     $tproot->AddChild(new CNode('note', "Instantiated from template {$tpname}"));
     $basemap->Convert(0, $tproot, 1, $this->_serv->GetRootNode());
     $s_vhnode->RemoveFromParent();
     $domains = $s_vhnode->GetChildVal('vhDomain');
     if ($domains == NULL) {
         $domains = $vhname;
     }
     // default
     if (($domainalias = $s_vhnode->GetChildVal('vhAliases')) != NULL) {
         $domains .= ", {$domainalias}";
     }
     $listeners = $s_tpnode->GetChildVal('listeners');
     $lns = preg_split("/, /", $listeners, -1, PREG_SPLIT_NO_EMPTY);
     foreach ($lns as $ln) {
         $listener = $this->_serv->GetChildNodeById('listener', $ln);
         if ($listener != NULL) {
             $vhmap = new CNode('vhmap', $vhname);
             $vhmap->AddChild(new CNode('domain', $domains));
             $listener->AddChild($vhmap);
         } else {
             error_log("cannot find listener {$ln} \n");
         }
     }
     $this->_serv->SaveFile();
     return true;
 }