X-Git-Url: https://git.llucax.com/software/bife/bife-all.git/blobdiff_plain/6040f3feab69010487b3e9b5b7ad532a0f44c50c..884d958d4c76bed1625460b591c599094f7690c8:/src/BIFE/Parser.php diff --git a/src/BIFE/Parser.php b/src/BIFE/Parser.php index 78ab5b0..4598ea1 100644 --- a/src/BIFE/Parser.php +++ b/src/BIFE/Parser.php @@ -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,12 +69,14 @@ class BIFE_Parser { /** * Constructor. * + * @param string $fallback Fallback class name (none if empty). + * * @return void * @access public */ - function BIFE_Parser() // ~X2C + function BIFE_Parser($fallback = '') // ~X2C { - $this->__construct($template); + $this->__construct($fallback); } // -X2C @@ -84,15 +84,17 @@ class BIFE_Parser { /** * Constructor. * + * @param string $fallback Fallback class name (none if empty). + * * @return void * @access public */ - function __construct() // ~X2C + function __construct($fallback = '') // ~X2C { $this->stack = array(); $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'); @@ -127,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); @@ -136,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 @@ -251,4 +262,4 @@ class BIFE_Parser { } // -X2C Class :Parser -?> +?> \ No newline at end of file