X-Git-Url: https://git.llucax.com/software/bife/bife-all.git/blobdiff_plain/6b3b1dd0cad8c4342008f139922e1ed26924bf2a..537561c5709c3f574c5d406cb4cb28b3522f2566:/src/BIFE/Parser.php diff --git a/src/BIFE/Parser.php b/src/BIFE/Parser.php index a084a4e..bf96326 100644 --- a/src/BIFE/Parser.php +++ b/src/BIFE/Parser.php @@ -34,12 +34,12 @@ */ class BIFE_Parser { /** - * Output string. + * Top level widget. * - * @var string $output + * @var BIFE_Widget $root * @access public */ - var $output; + var $root; /** * XML parser resource. @@ -50,20 +50,18 @@ class BIFE_Parser { var $parser; /** - * Template to use to render the parsed file. + * BIFE widgets stack. * - * @var HTML_Template_Sigma $template + * @var array $stack * @access public */ - var $template; + var $stack; /** - * BIFE widgets stack. - * - * @var array $stack + * @var string $fallback * @access public */ - var $stack; + var $fallback; // ~X2C @@ -71,14 +69,14 @@ class BIFE_Parser { /** * Constructor. * - * @param HTML_Template_Sigma &$template Template to use to render the widgets. + * @param string $fallback Fallback class name (none if empty). * * @return void * @access public */ - function BIFE_Parser(&$template) // ~X2C + function BIFE_Parser($fallback = '') // ~X2C { - $this->__construct($template); + $this->__construct($fallback); } // -X2C @@ -86,17 +84,17 @@ class BIFE_Parser { /** * Constructor. * - * @param HTML_Template_Sigma &$template Template to use to render the widgets. + * @param string $fallback Fallback class name (none if empty). * * @return void * @access public */ - function __construct(&$template) // ~X2C + function __construct($fallback = '') // ~X2C { $this->stack = array(); - $this->output = ''; + $this->root = null; $this->parser = xml_parser_create(); - $this->template =& $template; + $this->fallback = $fallback; xml_set_object($this->parser, $this); xml_set_element_handler($this->parser, 'startElement', 'endElement'); xml_set_character_data_handler($this->parser, 'characterData'); @@ -131,7 +129,7 @@ class BIFE_Parser { { $class = "BIFE_$name"; if (!class_exists($class)) { - include_once 'BIFE/' . ucfirst(strtolower($name)) . '.php'; + @include_once 'BIFE/' . ucfirst(strtolower($name)) . '.php'; } if (class_exists($class)) { $obj =& new $class($attrs); @@ -140,7 +138,16 @@ class BIFE_Parser { } $this->stack[] =& $obj; } else { - trigger_error("Class not found '$class'.", E_USER_ERROR); + if ($this->fallback) { + $class = $this->fallback; + $obj =& new $class($name, $attrs); + if (!is_a($obj, 'bife_fallback')) { + trigger_error("Class '$class' is not a BIFE_Fallback.", E_USER_WARNING); + } + $this->stack[] =& $obj; + } else { + trigger_error("Class not found '$class'.", E_USER_ERROR); + } } } // -X2C @@ -163,9 +170,9 @@ class BIFE_Parser { end($this->stack); $parent =& $this->stack[key($this->stack)]; if ($parent) { - $parent->addContents($current->render($this->template)); + $parent->addContents($current); } else { - $this->output = $current->render($this->template); + $this->root =& $current; } } // -X2C @@ -214,14 +221,14 @@ class BIFE_Parser { // +X2C Operation 37 /** - * Parse a XML file returning the rendered output. + * Parse a XML file with a complete and valid XML document. * * @param string $filename Filename to parse. * - * @return void + * @return &BIFE_Widget * @access public */ - function parseFile($filename) // ~X2C + function &parseFile($filename) // ~X2C { if ($fp = @fopen($filename, "r")) { while ($data = fread($fp, 4096)) { @@ -232,19 +239,24 @@ class BIFE_Parser { E_USER_WARNING); } fclose($fp); + return $this->root; } // -X2C - // +X2C Operation 38 + + // +X2C Operation 74 /** - * Get rendered output. + * Parse a XML string with a complete and valid XML document. + * + * @param string $data XML data to parse. * - * @return string + * @return &BIFE_Widget * @access public */ - function getOutput() // ~X2C + function &parseString($data) // ~X2C { - return $this->output; + $this->parse($data, true); + return $this->root; } // -X2C