From: Leandro Lucarella Date: Mon, 23 Jun 2003 03:27:16 +0000 (+0000) Subject: We are back with a functional revision. X-Git-Tag: svn_import~38 X-Git-Url: https://git.llucax.com/software/bife/bife-all.git/commitdiff_plain/b23b73b778ec0e241a0f13d0e2e592c35ef47743 We are back with a functional revision. - bife module is now called core and moved out from modules dir. - Fixed Parser to autoinclude files. - Root lost its sense since 'use' attribute lost it sense with Parser autoinclude (now the parser manages all needed includes). It might be gone in the future. - Updated example (it's working again). - Updated Makefiles (need some more work). --- diff --git a/modules/bife/BIFE/Container.php b/core/BIFE/Container.php similarity index 100% rename from modules/bife/BIFE/Container.php rename to core/BIFE/Container.php diff --git a/modules/bife/BIFE/Fallback.php b/core/BIFE/Fallback.php similarity index 100% rename from modules/bife/BIFE/Fallback.php rename to core/BIFE/Fallback.php diff --git a/modules/bife/BIFE/Parser.php b/core/BIFE/Parser.php similarity index 91% rename from modules/bife/BIFE/Parser.php rename to core/BIFE/Parser.php index cf0b851..83b39a3 100644 --- a/modules/bife/BIFE/Parser.php +++ b/core/BIFE/Parser.php @@ -37,31 +37,31 @@ class BIFE_Parser { * Top level widget. * * @var BIFE_Root $root - * @access public + * @access protected */ - var $root; + var $root = null; /** * XML parser resource. * * @var resource $parser - * @access public + * @access protected */ - var $parser; + var $parser = null; /** * BIFE widgets stack. * * @var array $stack - * @access public + * @access protected */ - var $stack; + var $stack = array(); /** * Fallback class to use in case that a widget class is not found. * * @var string $fallback - * @access public + * @access protected */ var $fallback = ''; @@ -73,6 +73,14 @@ class BIFE_Parser { */ var $cache = '/tmp'; + /** + * Files required by the parsed XML file. + * + * @var array $requires + * @access protected + */ + var $requires = array(); + // ~X2C // +X2C Operation 30 @@ -103,8 +111,6 @@ class BIFE_Parser { */ function __construct($fallback = '', $cache = '/tmp') // ~X2C { - $this->stack = array(); - $this->root = null; $this->parser = xml_parser_create(); $this->fallback = $fallback; $this->cache = $cache; @@ -140,12 +146,18 @@ class BIFE_Parser { */ function startElement($parser, $name, $attrs) // ~X2C { - $class = "BIFE_$name"; + $class = 'bife_' . strtolower(strtr($name, ':', '_')); if (!class_exists($class)) { - @include_once 'BIFE/' . ucfirst(strtolower($name)) . '.php'; + $inc = 'BIFE/' . + strtr(ucwords(strtr(strtolower($name), ':', ' ')), ' ', '/') . + '.php'; + if (@include_once $inc) { + $this->includes[] = $inc; + } } if (class_exists($class)) { $obj =& new $class($attrs); + // XXX - Does this check make sense? if (!is_a($obj, 'bife_widget')) { trigger_error("Class '$class' is not a BIFE_Widget.", E_USER_WARNING); } @@ -246,10 +258,9 @@ class BIFE_Parser { 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; + include_once $required; } return unserialize(join('', $file)); } @@ -265,7 +276,7 @@ class BIFE_Parser { fclose($fp); if ($this->cache) { $fp = fopen($cache, 'w'); - fputs($fp, serialize($this->root->getRequiredFiles()) . "\n"); + fputs($fp, serialize($this->includes) . "\n"); fputs($fp, serialize($this->root)); fclose($fp); } @@ -273,7 +284,6 @@ class BIFE_Parser { } // -X2C - // +X2C Operation 74 /** * Parse a XML string with a complete and valid XML document. @@ -292,4 +302,4 @@ class BIFE_Parser { } // -X2C Class :Parser -?> \ No newline at end of file +?> diff --git a/modules/bife/BIFE/Root.php b/core/BIFE/Root.php similarity index 97% rename from modules/bife/BIFE/Root.php rename to core/BIFE/Root.php index 5ce9f8f..cc4e74d 100644 --- a/modules/bife/BIFE/Root.php +++ b/core/BIFE/Root.php @@ -74,6 +74,7 @@ class BIFE_Root extends BIFE_Container { */ function __construct($attrs) // ~X2C { + /* if (@$attrs['USE']) { foreach (split(':', $attrs['USE']) as $require) { require_once "BIFE/$require.php"; @@ -81,13 +82,14 @@ class BIFE_Root extends BIFE_Container { } unset($attrs['USE']); } + */ parent::__construct($attrs); } // -X2C // +X2C Operation 150 /** - * Gets required files. + * Gets required files. (FIXME - DEPRECATED) * * @return array * @access public @@ -100,4 +102,4 @@ class BIFE_Root extends BIFE_Container { } // -X2C Class :Root -?> \ No newline at end of file +?> diff --git a/modules/bife/BIFE/Widget.php b/core/BIFE/Widget.php similarity index 100% rename from modules/bife/BIFE/Widget.php rename to core/BIFE/Widget.php diff --git a/modules/bife/HTML/Template/HIT.php b/core/HTML/Template/HIT.php similarity index 100% rename from modules/bife/HTML/Template/HIT.php rename to core/HTML/Template/HIT.php diff --git a/modules/bife/Makefile b/core/Makefile similarity index 73% rename from modules/bife/Makefile rename to core/Makefile index 8e60104..ed9979c 100644 --- a/modules/bife/Makefile +++ b/core/Makefile @@ -25,11 +25,38 @@ # $Id$ # +VERSION=0.10 +MODULE_FILE=BIFE.php +MODULE_NAME=Core +PHP_FILES=$(filter-out $(MODULE_FILE),$(subst ./,,$(shell find -name '*.php'))) +X2C_TEMPLATE=../xmi2code.tpl.php + +all: $(MODULE_FILE) + code: bife.xmi xmi2code.config @xmi2code -clean-code: +code-clean: @find -name '*.bak' | xargs rm -vf -clean: clean-code - +$(MODULE_FILE): code $(PHP_FILES) $(X2C_TEMPLATE) + @( \ + ( \ + cat $(X2C_TEMPLATE) | \ + grep -v '@@date' | \ + grep -v '$$Id' | \ + egrep -v '^//$$' \ + ); \ + echo '//'; \ + echo -n '// BIFE $(MODULE_NAME) (version $(VERSION)) - '; \ + date; \ + echo '//'; \ + ( \ + cat $(PHP_FILES) | \ + grep -v require_once | \ + grep -v '?>' | \ + grep -v '' \ + ) > $(MODULE_FILE) diff --git a/modules/bife/bife.xmi b/core/bife.xmi similarity index 95% rename from modules/bife/bife.xmi rename to core/bife.xmi index 095b32c..d324b80 100644 --- a/modules/bife/bife.xmi +++ b/core/bife.xmi @@ -5,11 +5,11 @@ umbrello uml modeller http://uml.sf.net 1.1 - + - + @@ -71,11 +71,12 @@ - - - - + + + + + @@ -95,7 +96,7 @@ - + @@ -145,7 +146,7 @@ Parse a template appending the results to an internal buffer. If $vars is an arr - + @@ -194,7 +195,7 @@ Parse a template appending the results to an internal buffer. If $vars is an arr - + @@ -206,6 +207,7 @@ Parse a template appending the results to an internal buffer. If $vars is an arr + diff --git a/modules/bife/xmi2code.config b/core/xmi2code.config similarity index 100% rename from modules/bife/xmi2code.config rename to core/xmi2code.config diff --git a/examples/index.php b/examples/index.php index 72fc369..f7abe2b 100644 --- a/examples/index.php +++ b/examples/index.php @@ -26,20 +26,22 @@ // $Id$ // +$incs = array( + '../core', + '../modules/album', + '../modules/basic', + '../modules/menu', +// '../modules/', +); $tmp = ini_get('include_path'); -ini_set('include_path', "../src:$tmp"); +ini_set('include_path', join(':', $incs) . ":$tmp"); unset($tmp); umask('002'); require_once 'HTML/Template/HIT.php'; require_once 'BIFE/Parser.php'; require_once 'BIFE/Copy.php'; -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/examples/index.xbf b/examples/index.xbf index 61383a8..4ace0c3 100644 --- a/examples/index.xbf +++ b/examples/index.xbf @@ -1,7 +1,7 @@ - + Datos!

Photo album

- +
diff --git a/examples/photo.xbf b/examples/photo.xbf index 5ead3ee..ba7f57c 100644 --- a/examples/photo.xbf +++ b/examples/photo.xbf @@ -1,4 +1,4 @@ - + diff --git a/modules/album/BIFE/Album/Pager.php b/modules/album/BIFE/Album/Pager.php index 76bb71a..577ce96 100644 --- a/modules/album/BIFE/Album/Pager.php +++ b/modules/album/BIFE/Album/Pager.php @@ -29,7 +29,7 @@ // +X2C includes -require_once 'BIFE.php'; +require_once 'BIFE/Widget.php'; // ~X2C // +X2C Class 151 :Pager diff --git a/modules/album/BIFE/Album/Photo.php b/modules/album/BIFE/Album/Photo.php index 6569eb8..1568255 100644 --- a/modules/album/BIFE/Album/Photo.php +++ b/modules/album/BIFE/Album/Photo.php @@ -27,7 +27,7 @@ // // +X2C includes -require_once 'BIFE.php'; +require_once 'BIFE/Widget.php'; // ~X2C // +X2C Class 103 :Photo diff --git a/modules/album/BIFE/Album/Thumbs.php b/modules/album/BIFE/Album/Thumbs.php index f79e525..7c5ddec 100644 --- a/modules/album/BIFE/Album/Thumbs.php +++ b/modules/album/BIFE/Album/Thumbs.php @@ -27,7 +27,7 @@ // // +X2C includes -require_once 'BIFE.php'; +require_once 'BIFE/Widget.php'; // ~X2C require_once 'Image/Transform.php'; diff --git a/modules/album/Makefile b/modules/album/Makefile index fd3a19d..63584a1 100644 --- a/modules/album/Makefile +++ b/modules/album/Makefile @@ -25,11 +25,11 @@ # $Id$ # -code: album.xmi xmi2code.config +MODULE=album + +code: $(MODULE).xmi xmi2code.config @xmi2code -clean-code: +code-clean: @find -name '*.bak' | xargs rm -vf -clean: clean-code - diff --git a/modules/album/album.xmi b/modules/album/album.xmi index 3626421..455bba5 100644 --- a/modules/album/album.xmi +++ b/modules/album/album.xmi @@ -12,8 +12,7 @@ +x2c:extern" name="Widget" static="0" scope="200" /> diff --git a/modules/basic/BIFE/Copy.php b/modules/basic/BIFE/Copy.php index 28491be..f58dec1 100644 --- a/modules/basic/BIFE/Copy.php +++ b/modules/basic/BIFE/Copy.php @@ -27,7 +27,7 @@ // // +X2C includes -require_once 'BIFE.php'; +require_once 'BIFE/Fallback.php'; // ~X2C // +X2C Class 76 :Copy diff --git a/modules/basic/BIFE/Generic.php b/modules/basic/BIFE/Generic.php index 5cac4c2..bbda5bd 100644 --- a/modules/basic/BIFE/Generic.php +++ b/modules/basic/BIFE/Generic.php @@ -27,7 +27,7 @@ // // +X2C includes -require_once 'BIFE.php'; +require_once 'BIFE/Container.php'; // ~X2C // +X2C Class 7 :Generic diff --git a/modules/basic/BIFE/Page.php b/modules/basic/BIFE/Page.php index a83aaaf..0bff2f9 100644 --- a/modules/basic/BIFE/Page.php +++ b/modules/basic/BIFE/Page.php @@ -27,7 +27,7 @@ // // +X2C includes -require_once 'BIFE.php'; +require_once 'BIFE/Root.php'; // ~X2C // +X2C Class 14 :Page diff --git a/modules/basic/Makefile b/modules/basic/Makefile index d2889c8..1aa829a 100644 --- a/modules/basic/Makefile +++ b/modules/basic/Makefile @@ -25,11 +25,11 @@ # $Id$ # -code: basic.xmi xmi2code.config +MODULE=basic + +code: $(MODULE).xmi xmi2code.config @xmi2code -clean-code: +code-clean: @find -name '*.bak' | xargs rm -vf -clean: clean-code - diff --git a/modules/basic/basic.xmi b/modules/basic/basic.xmi index 43917ff..b1e52f4 100644 --- a/modules/basic/basic.xmi +++ b/modules/basic/basic.xmi @@ -5,15 +5,14 @@ umbrello uml modeller http://uml.sf.net 1.1 - + +x2c:extern" name="Container" static="0" scope="200" /> @@ -51,8 +50,7 @@ x2c:include: BIFE.php" name="Container" static="0" scope="200" /> +x2c:extern" name="Fallback" static="0" scope="200" /> @@ -67,8 +65,7 @@ x2c:include: BIFE.php" name="Fallback" static="0" scope="200" /> +x2c:extern" name="Root" static="0" scope="200" /> diff --git a/modules/menu/BIFE/Menu/Menu.php b/modules/menu/BIFE/Menu/Menu.php index e4a3b8d..0c3d4ef 100644 --- a/modules/menu/BIFE/Menu/Menu.php +++ b/modules/menu/BIFE/Menu/Menu.php @@ -29,7 +29,7 @@ // +X2C includes -require_once 'BIFE.php'; +require_once 'BIFE/Widget.php'; // ~X2C // +X2C Class 115 :Menu diff --git a/modules/menu/Makefile b/modules/menu/Makefile index 9d04db6..3aedb00 100644 --- a/modules/menu/Makefile +++ b/modules/menu/Makefile @@ -25,11 +25,11 @@ # $Id$ # -code: menu.xmi xmi2code.config +MODULE=menu + +code: $(MODULE).xmi xmi2code.config @xmi2code -clean-code: +code-clean: @find -name '*.bak' | xargs rm -vf -clean: clean-code - diff --git a/modules/menu/menu.xmi b/modules/menu/menu.xmi index 57cb170..5fb8ff5 100644 --- a/modules/menu/menu.xmi +++ b/modules/menu/menu.xmi @@ -12,8 +12,7 @@ +x2c:extern" name="Widget" static="0" scope="200" /> @@ -31,14 +30,14 @@ x2c:extern" name="HIT" static="0" scope="200" /> - + - +