Пример #1
0
 public static function loadStaticConfig($pref, $pre, $path = '', $file = null)
 {
     CConfig::$onload = true;
     if ($path != '') {
         $path .= '/';
     }
     $path = str_replace("\\", '/', $path);
     $ff = $path . $pre . CConfig::$CONF_FILE;
     if ($file != null) {
         $ff = $path . $file;
     }
     if (file_exists($ff)) {
         // file was found, create a Component object from file content
         $com = Component::decodeComponent(file_get_contents($ff));
         $com->setPrefix($pref);
         // check if the links
         // know their prefixes
         $conf = $com;
         $links = $conf->getLinks();
         // always been an array
         if (!is_array($links)) {
             $links = array($links);
         }
         $changed = false;
         foreach ($links as &$link) {
             // if a link has no prefix, we have to ask the link target
             // for the prefix list
             if ($link->getPrefix() === null) {
                 $result = Request::get($link->getAddress() . '/control', array(), '');
                 if ($result['status'] == 200) {
                     // the link target has send its component definition,
                     // so that we can remember this
                     $changed = true;
                     $obj = Component::decodeComponent($result['content']);
                     $link->setPrefix($obj->getPrefix());
                     $link->setClassFile($obj->getClassFile());
                     $link->setClassName($obj->getClassName());
                     $link->setLocalPath($obj->getLocalPath());
                 }
             }
         }
         // if any new prefix was found, we have to store the link definitions
         if ($changed) {
             $conf->setLinks($links);
             CConfig::saveConfigGlobal($pre, Component::encodeComponent($conf), substr($path, 0, -1), $file);
             $com = $conf;
         }
         CConfig::$onload = false;
         return $com;
     } else {
         // can't find the file, create an empty object
         $com = new Component();
         $com->setPrefix($pref);
         CConfig::$onload = false;
         return $com;
     }
     CConfig::$onload = false;
 }