From: Leandro Lucarella Date: Sat, 21 Jun 2003 20:22:56 +0000 (+0000) Subject: - Added cache capabilities to the Parser (activated by default). X-Git-Tag: svn_import~40 X-Git-Url: https://git.llucax.com/software/bife/bife-all.git/commitdiff_plain/5a38104a646a3e60a7c29f816f034691ae354351 - Added cache capabilities to the Parser (activated by default). - Added a list of required files to Root (and getRequiredFiles() method). - Now Parser::parseFile() and Parser::parseString() must return both a Root widget. - Updated UML diagram. - Updated ROADMAP. - Updated version numbers to future release. --- diff --git a/Doxyfile b/Doxyfile index 448b4a7..19e035a 100644 --- a/Doxyfile +++ b/Doxyfile @@ -30,7 +30,7 @@ # General configuration options #--------------------------------------------------------------------------- PROJECT_NAME = "BIFE - Build It FastEr" -PROJECT_NUMBER = 0.8 +PROJECT_NUMBER = 0.10 OUTPUT_DIRECTORY = doc/api OUTPUT_LANGUAGE = English EXTRACT_ALL = YES diff --git a/Makefile b/Makefile index 70f7383..407e379 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ # $Id$ # -VERSION=0.8 +VERSION=0.10 PHP_FILES=src/BIFE/*.php META_FILES=xmi2code.config xmi2code.tpl.php Makefile Doxyfile package.xml DOC_FILES=doc/bife.xmi diff --git a/doc/ROADMAP b/doc/ROADMAP index f506a63..8b4ec37 100644 --- a/doc/ROADMAP +++ b/doc/ROADMAP @@ -3,9 +3,9 @@ $Id$ Version 0.10 ============ - - Add XML file caching. + - Add XML file caching (done!). - Make a way to put all classes in a package together in a single file to - avoid overhead in require_once calls. + avoid overhead in require_once calls (to be reviewed). - Make a Core Package with the core classes (Parser, Widget, Container, Root, Fallback). - Make a Basic (or Generic?) Package with simple implementations of all diff --git a/doc/bife.xmi b/doc/bife.xmi index bd9743d..b8a9ac7 100644 --- a/doc/bife.xmi +++ b/doc/bife.xmi @@ -5,11 +5,11 @@ umbrello uml modeller http://uml.sf.net 1.1 - + - + @@ -108,9 +108,11 @@ Returns an array of associative arrays with this keys: + + @@ -130,16 +132,17 @@ Returns an array of associative arrays with this keys: - + - + - + - + + @@ -172,6 +175,8 @@ Returns an array of associative arrays with this keys: + + @@ -249,235 +254,235 @@ Parse a template appending the results to an internal buffer. If $vars is an arr - - - - - + + + + + - - + + - - + + - - + + - - - + + + - - + + - - - - - - - - + + + + + + + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - - + + + - - + + - - + + - - + + - - + + - - - - - - - - - - - - - + + + + + + + + + + + + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - - + + + - - + + - + @@ -504,7 +509,6 @@ Parse a template appending the results to an internal buffer. If $vars is an arr - @@ -513,9 +517,9 @@ Parse a template appending the results to an internal buffer. If $vars is an arr - + @@ -524,9 +528,9 @@ Parse a template appending the results to an internal buffer. If $vars is an arr - + @@ -536,9 +540,9 @@ Parse a template appending the results to an internal buffer. If $vars is an arr - + @@ -548,17 +552,18 @@ Parse a template appending the results to an internal buffer. If $vars is an arr - + - + + - + @@ -566,22 +571,24 @@ Parse a template appending the results to an internal buffer. If $vars is an arr + + - + + + - - @@ -599,6 +606,7 @@ Parse a template appending the results to an internal buffer. If $vars is an arr + diff --git a/examples/index.php b/examples/index.php index b748728..d00262c 100644 --- a/examples/index.php +++ b/examples/index.php @@ -39,6 +39,7 @@ require_once 'BIFE/Page.php'; require_once 'BIFE/Title.php'; require_once 'BIFE/Link.php'; #require_once 'BIFE/Album.php'; +#require_once 'BIFE/AlbumPhoto.php'; #require_once 'BIFE.php'; $file = isset($_REQUEST['BIFE']) ? $_REQUEST['BIFE'] : 'index.xbf'; diff --git a/src/BIFE/Album.php b/src/BIFE/Album.php index a98c716..52af679 100644 --- a/src/BIFE/Album.php +++ b/src/BIFE/Album.php @@ -269,4 +269,4 @@ Returns an array of associative arrays with this keys: } // -X2C Class :Album -?> +?> \ No newline at end of file diff --git a/src/BIFE/Parser.php b/src/BIFE/Parser.php index 4598ea1..cf0b851 100644 --- a/src/BIFE/Parser.php +++ b/src/BIFE/Parser.php @@ -36,7 +36,7 @@ class BIFE_Parser { /** * Top level widget. * - * @var BIFE_Widget $root + * @var BIFE_Root $root * @access public */ var $root; @@ -58,10 +58,20 @@ class BIFE_Parser { var $stack; /** + * Fallback class to use in case that a widget class is not found. + * * @var string $fallback * @access public */ - var $fallback; + var $fallback = ''; + + /** + * XML cache directory. Empty if no cahching must be done (for current dir use '.'). + * + * @var string $cache + * @access protected + */ + var $cache = '/tmp'; // ~X2C @@ -70,13 +80,14 @@ class BIFE_Parser { * Constructor. * * @param string $fallback Fallback class name (none if empty). + * @param string $cache XML cache directory. Empty is no caching will be done. * * @return void * @access public */ - function BIFE_Parser($fallback = '') // ~X2C + function BIFE_Parser($fallback = '', $cache = '/tmp') // ~X2C { - $this->__construct($fallback); + $this->__construct($fallback, $cache); } // -X2C @@ -85,16 +96,18 @@ class BIFE_Parser { * Constructor. * * @param string $fallback Fallback class name (none if empty). + * @param string $cache XML cache directory. Empty is no caching will be done. * * @return void * @access public */ - function __construct($fallback = '') // ~X2C + function __construct($fallback = '', $cache = '/tmp') // ~X2C { $this->stack = array(); $this->root = null; $this->parser = xml_parser_create(); $this->fallback = $fallback; + $this->cache = $cache; xml_set_object($this->parser, $this); xml_set_element_handler($this->parser, 'startElement', 'endElement'); xml_set_character_data_handler($this->parser, 'characterData'); @@ -225,12 +238,23 @@ class BIFE_Parser { * * @param string $filename Filename to parse. * - * @return &BIFE_Widget + * @return &BIFE_Root * @access public */ function &parseFile($filename) // ~X2C { - if ($fp = @fopen($filename, "r")) { + if ($this->cache) { + $cache = $this->cache . '/' . 'bife_parser_cache' . strtr(realpath($filename), '/', '_'); + if (@filemtime($cache) > @filemtime($filename)) { + // FIXME - replace with file_get_contents() + $file = file($cache); + foreach(unserialize(trim(array_shift($file))) as $required) { + require_once $required; + } + return unserialize(join('', $file)); + } + } + if ($fp = @fopen($filename, 'r')) { while ($data = fread($fp, 4096)) { $this->parse($data, feof($fp)); } @@ -239,6 +263,12 @@ class BIFE_Parser { E_USER_WARNING); } fclose($fp); + if ($this->cache) { + $fp = fopen($cache, 'w'); + fputs($fp, serialize($this->root->getRequiredFiles()) . "\n"); + fputs($fp, serialize($this->root)); + fclose($fp); + } return $this->root; } // -X2C @@ -250,7 +280,7 @@ class BIFE_Parser { * * @param string $data XML data to parse. * - * @return &BIFE_Widget + * @return &BIFE_Root * @access public */ function &parseString($data) // ~X2C diff --git a/src/BIFE/Root.php b/src/BIFE/Root.php index 66f9cbc..f18f008 100644 --- a/src/BIFE/Root.php +++ b/src/BIFE/Root.php @@ -37,6 +37,14 @@ require_once 'BIFE/Container.php'; * @access public */ class BIFE_Root extends BIFE_Container { + /** + * Root widget's required files. + * + * @var array $required + * @access protected + */ + var $required = array(); + // ~X2C // +X2C Operation 87 @@ -68,6 +76,7 @@ class BIFE_Root extends BIFE_Container { if (@$attrs['USE']) { foreach (split(':', $attrs['USE']) as $require) { require_once "BIFE/$require.php"; + $this->required[] = "BIFE/$require.php"; } unset($attrs['USE']); } @@ -75,6 +84,19 @@ class BIFE_Root extends BIFE_Container { } // -X2C + // +X2C Operation 150 + /** + * Gets required files. + * + * @return array + * @access public + */ + function getRequiredFiles() // ~X2C + { + return $this->required; + } + // -X2C + } // -X2C Class :Root ?> \ No newline at end of file diff --git a/src/HTML/Template/HIT.php b/src/HTML/Template/HIT.php index 6da0b7b..025707a 100644 --- a/src/HTML/Template/HIT.php +++ b/src/HTML/Template/HIT.php @@ -119,6 +119,7 @@ If $vars is an array, the {[keys]} are replaced with [values] ($val is ignored). $file = "{$this->root}/$name.tpl.html"; } if (!isset($this->cache[$file])) { + // FIXME - replace join(file()) with file_get_contents(). $this->cache[$file] = join('', file($file)); } //if (!is_readable($file)) {