valueTree = new VariableValueTree(); $this->informationTree = new VariableInformationTree(); $currentValueChild = $this->valueTree; // $this->valueTree->setPrefix(basename(strtoupper($file))); $matches = null; $sortedMatches = null; $commentStarted = null; foreach (new FileIterator($file) as $lineNo => $line) { if($line == "\n" || $line == "\r" || $line == "\n\r" || $line == "\r\n") { unset($lastVariableValue); $currentValueChild->add(new EmptyLine()); continue; } unset ($matches); unset ($sortedMatches); if(!isset($commentContent)) $commentContent = ""; if (ereg("^([^:space:#]*)='([^']*)'[:space:]*(.*)$", $line, $matches)) { // Wenn der Variablen-Wert nicht mit " eingeschlossen ist, wird versucht ' zu benutzen $commentStarted = false; } elseif (ereg('^([^:space:#]*)="([^"]*)"[:space:]*(.*)$', $line, $matches)) { $commentStarted = false; } else { // Kommentar if (preg_match("/^#[-]+/", $line)) { if ($commentStarted) { $this->valueTree->add(new ConfigTitle(trim($commentContent))); unset ($commentContent); } $commentStarted = !$commentStarted; } elseif ($commentStarted) { $commentContent .= trim($line) . Literals::get("LINEFEED"); } elseif(isset($lastVariableValue)) { $lastVariableValue->addToComment(trim($line)); } else { $currentValueChild->add(new Comment(trim($line))); } continue; } if (count($matches) < 2) throw new Exception("Syntaxerror in Zeile $lineNo"); $varName = $matches[1]; $varValue = $matches[2]; $varComment = trim($matches[3]); $matches = preg_split("/_([0-9]+)[_]?/", $varName, -1, PREG_SPLIT_DELIM_CAPTURE); if($matches[count($matches)-1] == "") unset($matches[count($matches)-1]); // Ergebnis puffern damit das anschließende foreach auf den Index und den Namen zugegriffen werden kann ($sortedMatches[] = array(%index%, %Inhalt%) $index = 0; if (count($matches > 1)) { foreach ($matches as $match) { if (is_numeric($match)) { $index = $match; } else { $sortedMatches[] = array ($index, $match ); unset($index); } } if(isset($index)) { $sortedMatches[] = array ($index, null ); } } else { $sortedMatches = $matches; } /** * Zwei Bäume anlegen: * 1. Struktur wie in check-Datei (actElementData) * - Ein Objekt pro Variable * 2. Struktur wie in config-Datei (actElementContent) * - Ein Objekt pro Variablen-Wert */ $currentValueChild = $this->valueTree; $currentInformationChild = $this->informationTree; foreach ($sortedMatches as $matchData) { list ($index, $varNamePart) = $matchData; // echo $varNamePart."_".$index."\n"; // Wenn der Variablen-Teil bereits besteht, kein neues Objekt anlegen sondern Referenz auf vorhandenes setzen. if (!$currentInformationChild->isName($varNamePart)) $currentInformationChild = $currentInformationChild->add(new VariableInformationTree($varNamePart)); else $currentInformationChild = $currentInformationChild->getChildByName($varNamePart); /** * Wenn die Variablen-Teil-Position bereits besteht, kein neues Objekt anlegen sondern Referenz auf vorhandenes setzen. * Wenn wir in der obersten Ebene sind (z.B. START_ASTERISK=...), sind keine Positionen vorhanden, also immer anlegen. */ if($index == 0) $currentValueChild = $this->valueTree; elseif (!$currentValueChild->testPosInChildren($index)) $currentValueChild = $currentValueChild->add(new VariableIndex($index)); else $currentValueChild = $currentValueChild->getChildByPos($index); if(!$currentValueChild->testNameInChildren($varNamePart)) $currentValueChild = $currentValueChild->add(new VariableValueTree($currentInformationChild)); else $currentValueChild = $currentValueChild->getChildByName($varNamePart); } // Variablen-Wert als Leaf-Element an den Content-Baum anhängen. $lastVariableValue = $currentValueChild->add(new VariableValue($varValue, $varComment)); } // Falls ein Kommentar nicht mit #---... geschlossen wurde if (!empty ($commentContent)) $this->valueTree->add(new configTitle(trim($commentContent))); } /** * * @return VariableValueTree */ public function getValueTree() { return $this->valueTree; } /** * * @return VariableInformationTree */ public function getInformationTree() { return $this->informationTree; } } // end of ReadConfig ?>