|
From: andi <bin...@li...> - 2001-09-21 18:17:34
|
andi Fri Sep 21 11:17:24 2001 EDT
Modified files:
/r2/binarycloud/base/lib BCTagParser.php
Log:
Cleared up and documented the parser.
Index: r2/binarycloud/base/lib/BCTagParser.php
diff -u r2/binarycloud/base/lib/BCTagParser.php:1.2 r2/binarycloud/base/lib/BCTagParser.php:1.3
--- r2/binarycloud/base/lib/BCTagParser.php:1.2 Fri Sep 21 08:34:35 2001
+++ r2/binarycloud/base/lib/BCTagParser.php Fri Sep 21 11:17:24 2001
@@ -1,49 +1,98 @@
-#!/usr/local/php4/bin/php -q
<?php
+// Header {{{
+/*
+ * -File $Id: BCTagParser.php,v 1.3 2001/09/21 18:17:24 andi Exp $
+ * -License LGPL (http://www.gnu.org/copyleft/lesser.html)
+ * -Copyright 2001, Thyrell
+ * -Authors Andreas Aderhold, <a.a...@th...>
+ */
-// these are the actual compiling methods.
-// They are registered at setup they must
-// return a sting with the compiled data,
-// or null in case of a compile error
-
-function BCCompileModuleTag($_tags) {
- // translating xml to php by using XMLUtils
- // this seems not to work for tag attributes
+$PACKAGE='binarycloud.lib';
- $trees = XMLUtils::XMLStr2XML($_tags);
- $xmlTree=$trees[0];
- $phpTree = XMLUtils::XML2PHP($xmlTree);
- $txtTree = XMLUtils::PHP2PHPArr($phpTree,false);
- var_dump($phpTree);
- return "Module Compiler output";
-}
+// }}}
+// {{{ BCTagParser
+/**
+ * BCTagParser class.
+ *
+ *
+ * @author Andreas Aderhold, a.a...@th...
+ * @version $Id: BCTagParser.php,v 1.3 2001/09/21 18:17:24 andi Exp $
+ */
-function BCCompileImgTag($_tag) {
- return "<img src=\"example_compliler_output.gif\">";
-}
-?>
-<?php
-// here we go
class BCTagParser {
/** Pool of all registered bc:foo tags and processor methods */
- var $knownTags = array(); // list of kown tags and their compiler methods
- var $infile = null; // source file
- var $outfile = null; // file to write back
-
+ var $knownTags = array();
+
+ /** source and destination files */
+ var $infile = null;
+ var $outfile = null;
+
+ // BCTagParser($_infile, $_outfile) {{{
+ /**
+ * Constructor. Set in und out file
+ *
+ * @param string filename of the sourcefile
+ * @param string filename of destination file
+ * @access public
+ * @author Andreas Aderhold, <a.a...@th...>
+ */
+
function BCTagParser($_infile, $_outfile) {
$this->infile = $_infile;
$this->outfile = $_outfile;
}
+
+ // }}}
+ // Compile() {{{
+ /**
+ * Compile. Assesor that starts the compiling process.
+ *
+ * @access public
+ * @author Andreas Aderhold, <a.a...@th...>
+ */
function Compile() {
$this->_CompileFile();
}
+ // }}}
+ // RegisterTag($_tag, $_processor) {{{
+ /**
+ * Register tag method. Registers a bc-style tag and the relating
+ * compiler function.
+ *
+ * i.e. $this->RegisterTag('BC:MODULE','BCCompileModuleTag');
+ *
+ * @access public
+ * @author Andreas Aderhold, <a.a...@th...>
+ */
+
function RegisterTag($_tag, $_processor) {
$this->knownTags[strtoupper($_tag)] = $_processor;
}
+ // }}}
+ // _CompileFile() {{{
+ /**
+ * Compiles file. Runs over the infile and looks for bc-style tags.
+ * Reads this tags to a buffer and builds an array with tag data
+ * and tag metadata (name, compiler handler, tagdata). Passes the
+ * tagdata to _CompileTag and replaces the tag with the compiled
+ * string in the outbuffer. Writes the outfile. The tagmeta array
+ * is in this form
+ *
+ * array(
+ * 'name' => 'BC:SOMETHING',
+ * 'handler' => 'BCCompileSomethingTag',
+ * 'data' => complete xml tag data
+ * );
+ *
+ * @return bool true/false upon success or failure
+ * @access public
+ * @author Andreas Aderhold, <a.a...@th...>
+ */
+
function _CompileFile() {
/* read file from disk */
@@ -70,7 +119,7 @@
}
}
}
- var_dump($tagData);
+
/* found at least one block, loop through and call compiler */
for ($i = 0; $i < count($tagData); $i++) {
echo "Compiling...\n";
@@ -78,19 +127,19 @@
}
/* write the new file to disk */
- $this->_Writefile($this->outfile, $source);
-
+ $success = $this->_Writefile($this->outfile, $source);
+ return $success;
}
-
- // method _CompileTag($_data) {{{
+ // }}}
+ // _CompileTag($_data) {{{
/**
- * This calls the xml parser providing the tag to parse. And retuns the
- * compiled tag.
+ * This calls the compiler function. And retuns the compiled tag.
*
- * @param $_tag string the xml tag to parse
+ * @param string $_tag the xml tag data to parse
* @access private
*/
+
function _CompileTag($_data) {
$tName =& $_data['name'];
@@ -116,14 +165,17 @@
}
// }}}
- // method _Readfile($_filename) {{{
-
+ // _Readfile($_filename) {{{
/**
- * private method for reading a file into an internal buffer
+ * Private method for reading a file into a buffer
*
- * @param $_filename string the file to read
- * @return string the contents of the file
+ * @param string $_filename the file to read
+ * @return string the contents of the file
+ * @access private
+ * @author Monte Ohrt <mo...@is...>
+ * @author Andrei Zmievski <an...@ph...>
*/
+
function _Readfile($_filename) {
if (!($fd = fopen($_filename, 'r'))) {
die("problem reading '$_filename.'");
@@ -136,16 +188,18 @@
}
// }}}
- // {{{
-
+ // _Writefile($_filename, $_contents) {{{
/**
* private method for writing a file from an internal buffer.
- * Method stolen from smarty ;-)
*
- * @param $_filename string the file to write
- * @param $_contents string the data to write
+ * @param string $_filename the filename to write
+ * @param string $_contents the data to write
* @return bool
+ * @access private
+ * @author Monte Ohrt <mo...@is...>
+ * @author Andrei Zmievski <an...@ph...>
*/
+
function _Writefile($_filename, $_contents) {
if (!($fd = fopen($_filename, 'w'))) {
@@ -160,17 +214,32 @@
}
return true;
}
+
+ // }}}
}
// }}}
-?>
-<?php
-// runngin the parser for demonstration
-include_once('./XMLUtils.php');
+
+
+// these are the actual compiling methods.
+// They are registered at setup they must
+// return a sting with the compiled data,
+// or null in case of a compile error
+// might be useful to swap them to another file
+
+function BCCompileModuleTag($_tags) {
+ // translating xml to php by using XMLUtils
+ // this seems not to work for tag attributes
-$xml =& new BCTagParser("data.html.xml", "data.html");
-$xml->RegisterTag('BC:MODULE', "BCCompileModuleTag");
-$xml->RegisterTag('BC:IMG', "BCCompileImgTag");
-$xml->Compile();
+ $trees = XMLUtils::XMLStr2XML($_tags);
+ $xmlTree = $trees[0];
+ $phpTree = XMLUtils::XML2PHP($xmlTree);
+ $txtTree = XMLUtils::PHP2PHPArr($phpTree,false);
+ return $txtTree;
+}
+
+function BCCompileImgTag($_tag) {
+ return "<img src=\"example_compliler_output.gif\">";
+}
/*
* Local Variables:
|