doc = getGenericDomDocument('1.0'); $tag = $this->doc->createElement('circuit'); if($isPublic) { $tag->setAttribute('access', 'public'); } else { $tag->setAttribute('access', 'internal'); } $this->root = $this->doc->appendChild($tag); $this->root->appendChild($this->doc->createComment(" ")); //this forces circuits to have open & close tags (text node messes formatting up) $this->name = $name; $this->folder = $folder; $this->isOpen = true; } function addPrefuseaction($children = array()) { $tag = $this->doc->createElement('prefuseaction'); $this->lastFa = $this->root->appendChild($tag); //add children $this->addToLastTag($children); } function addPostfuseaction($children = array()) { $tag = $this->doc->createElement('postfuseaction'); $this->lastFa = $this->root->appendChild($tag); //add children $this->addToLastTag($children); } function addFa($faName, $children = array(), $isPublic = true) { $tag = $this->doc->createElement('fuseaction'); $tag->setAttribute('name', $faName); if(!$isPublic) { $tag->setAttribute('access', 'internal'); } $this->lastFa = $this->root->appendChild($tag); //add children $this->addToLastTag($children); } /* This function allows you to add additional tags conditionally, outside of the addFa() function arguments, but it opens the potential for bad grammar (eg. putting tags inside others which shouldn't be there) so you should only use it where necessary. */ function addToLastTag($tags) { //The tagStack must have a non-empty element to put stuff into if( !$this->lastFa ) { echo 'ERROR: Could not add tag, no elements exist to add to.'; return; } //If we only got one tag in the arguments, put it in an array so the loop below works if( gettype($tags) != 'array') { $tags = array($tags); } foreach($tags as $tag) { if($tag != null) { $this->lastFa->appendChild($tag); } } } function setTag($name, $value, $evaluate = false) { $tag = $this->doc->createElement('set'); $tag->setAttribute('name', $name); $tag->setAttribute('value', $value); if($evaluate) { $tag->setAttribute('evaluate', 'true'); } return $tag; } function save() { $results = array(); $results[] = array('circuitname' => $this->name); $content = $this->doc->saveXML(); make_directory($this->folder); $results[] = array('mkdir' => $this->folder); $filename = $this->folder.DIRSEP.CIRCUIT_FILENAME; if (!$handle = fopen($filename, 'w')) { $results[] = array('error' => 'Could not open file for writing (may already exist): '.$filename); } else { if (fwrite($handle, $content) === FALSE) { $results[] = array('error' => 'Could not write to file: '.$filename); } else { $results[] = array('circuitfile' => 'Wrote '.round(strlen($content) / 1024, 1).'K to '.$filename); } fclose($handle); } return $results; } } ?>