public static function parseList($varListStr)
 {
     $varList = array();
     $varStrArray = explode('\\n', $varListStr);
     foreach ($varStrArray as $varStr) {
         if (substr($varStr, 0, 1) == '$') {
             $var = new Varible();
             $var->parse($varStr);
             array_push($varList, $var);
         }
     }
     return $varList;
 }
Example #2
0
 function parse()
 {
     $fp = fopen($this->filePath, "r") or die("Couldnot open file");
     $varListStr = "";
     $checkListStr = "";
     $stepListStr = "";
     $collectListStr = "";
     while (!feof($fp)) {
         $line = trim(fgets($fp, 1024));
         $flag = substr($line, 0, 1);
         $elementArray = explode('.', $line, 2);
         $element = $elementArray[0];
         switch ($flag) {
             case "\$":
                 $varListStr .= $line . '\\n';
                 break;
             case "{":
                 $stepListStr .= $line . '\\nflag';
                 $checkListStr .= $line . '\\nflag';
                 $collectListStr .= $line . '\\nflag';
                 break;
             case "}":
                 $stepListStr .= $line . '\\n';
                 $checkListStr .= $line . '\\n';
                 $collectListStr .= $line . '\\n';
                 break;
             case "#":
                 break;
             default:
                 switch ($element) {
                     case "step":
                         $stepListStr .= $line . '\\n';
                         break;
                     case "check":
                         $checkListStr .= $line . '\\n';
                         break;
                     case "collect":
                         $collectListStr .= $line . '\\n';
                         break;
                     default:
                         break;
                 }
                 break;
         }
     }
     fclose($fp);
     //echo "</br></br>".$varListStr."</br></br>";
     //echo $checkListStr."</br></br>";
     //echo $stepListStr."</br></br>";
     //echo $collectListStr."</br></br>";
     $this->varibles = Varible::parseList($varListStr);
     $this->checks = Check::parseList($checkListStr, "check");
     $this->steps = Step::parseList($stepListStr, "step");
     $this->collects = Collect::parseList($collectListStr, "collect");
 }
Example #3
0
 function parse()
 {
     $fp = fopen($this->filePath, "r") or die("Couldnot open file");
     $confObj = array("var" => "", "check" => "", "step" => "", "collect" => "");
     $type = "";
     $num = 0;
     while (!feof($fp)) {
         $line = trim(fgets($fp, 1024));
         $head = substr($line, 0, 1);
         $elementArray = explode('.', $line, 2);
         $element = $elementArray[0];
         switch ($head) {
             case "\$":
                 $confObj["var"] .= $line . '\\nline_split';
                 break;
             case "{":
                 if ($type == "") {
                     $confObj["step"] .= '\\nmodule_split';
                     $confObj["check"] .= '\\nmodule_split';
                     $confObj["collect"] .= '\\nmodule_split';
                 } else {
                     if (array_key_exists($type, $confObj)) {
                         $confObj[$type] .= $line . '\\nline_split';
                         $num = $num + 1;
                     }
                 }
                 break;
             case "}":
                 if ($num == 0) {
                     $confObj["step"] .= '\\nline_split';
                     $confObj["check"] .= '\\nline_split';
                     $confObj["collect"] .= '\\nline_split';
                     $type = "";
                 } else {
                     if ($num > 0) {
                         $num = $num - 1;
                         $confObj[$type] .= $line . '\\nline_split';
                     }
                 }
                 break;
             case "#":
                 if (array_key_exists($type, $confObj)) {
                     $confObj[$type] .= $line . '\\nline_split';
                 }
                 break;
             default:
                 if (array_key_exists($type, $confObj)) {
                     $confObj[$type] .= $line . '\\nline_split';
                 } else {
                     if (array_key_exists($element, $confObj)) {
                         $confObj[$element] .= $line . '\\nline_split';
                         $type = $element;
                     }
                 }
                 break;
         }
     }
     fclose($fp);
     $this->varibles = Varible::parseList($confObj["var"]);
     $this->checks = Check::parseList($confObj["check"], "check");
     $this->steps = Step::parseList($confObj["step"], "step");
     //echo $confObj["step"];
     $this->collects = Collect::parseList($confObj["collect"], "collect");
 }
if (isset($confObjStr)) {
    if (get_magic_quotes_gpc()) {
        $confObjStr = stripslashes($confObjStr);
    }
}
$confObj = json_decode($confObjStr, true);
if ($confObj == null) {
    echo "1, 保存失败,配置文件为空";
    return;
}
try {
    // parse the vars
    $varlist = $confObj["vars"];
    $varObjlist = array();
    foreach ($varlist as $element) {
        $var = new Varible();
        $var->set($element[0], $element[1]);
        array_push($varObjlist, $var);
    }
    // parse steps and collects
    $stepObjlist = parse_element("step", $confObj);
    $collectObjlist = parse_element("collect", $confObj);
    $config = new Config($file_path);
    $config->varibles = $varObjlist;
    $config->steps = $stepObjlist;
    $config->collects = $collectObjlist;
    $config->write();
    echo "0, 配置文件保存成功";
} catch (Exception $e) {
    echo "1, 配置文件保存失败:" + $e;
}