Example #1
0
 public static function Init($data)
 {
     $component = new Component();
     $links = array();
     $link = new Link();
     $link->setName('fileDb');
     $link->setAddress('http://localhost/' . $data['path'] . '/fileDb');
     $link->setPrefix('file');
     $links[] = $link;
     $link = new Link();
     $link->setName('file');
     $link->setAddress('http://localhost/' . $data['path'] . '/file');
     $link->setPrefix('file');
     $links[] = $link;
     $component->setLinks($links);
     chdir(dirname(__FILE__));
     CConfig::saveConfigGlobal('', Component::encodeComponent($component));
 }
Example #2
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;
 }