[Phpcms-plugins-cvs] admin4phpCMS/include class.actionhandler.php,1.2,1.3 class.eventhandler.php,1.2
Brought to you by:
mjahn
From: Martin J. <mj...@us...> - 2004-05-30 18:04:22
|
Update of /cvsroot/phpcms-plugins/admin4phpCMS/include In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9898/include Modified Files: class.actionhandler.php class.eventhandler.php class.framework.php class.module.php Log Message: restructuring of some files Index: class.module.php =================================================================== RCS file: /cvsroot/phpcms-plugins/admin4phpCMS/include/class.module.php,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- class.module.php 26 May 2004 11:25:59 -0000 1.2 +++ class.module.php 30 May 2004 18:03:40 -0000 1.3 @@ -1,5 +1,40 @@ <?php - +/** +* Die Basis-Klasse des Modulsystems. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Martin Jahn <mj...@us...> +* @license GPL +* @copyright Copyright (c) 2004, Martin Jahn +* @version $Id$ +* @package admin4phpCMS +* +**/ +/* +* $Log$ +* Revision 1.3 2004/05/30 18:03:40 mjahn +* restructuring of some files +* +*/ +/** +* Basis-Klasse mit den grundlegenden Eigenschaften und Methoden eines Modules +* +* @package admin4phpCMS +* @access private +**/ class module { function module (&$eventhandler) { @@ -10,18 +45,18 @@ $this->_event =& $eventhandler; } - function __registerEvent ($eventname, $eventaction) { + function _registerEvent ($eventname, $eventaction) { $actiondata = array ('eventname'=>$eventname, 'eventaction'=>$eventaction); - $this->__callEvent ('REGISTER_EVENT', $actiondata); + $this->_callEvent ('REGISTER_EVENT', $actiondata); } - function &__callEvent ($eventname, &$actiondata) { + function &_callEvent ($eventname, &$actiondata) { return $this->_event->event ($eventname, $actiondata); } - function &__registerAction ($actionname, $method) { + function &_registerAction ($actionname, $method) { $actiondata = array ('actionname'=>$actionname, 'class'=>get_class($this), 'method'=>$method); - return $this->__callEvent ('REGISTER_ACTION', $actiondata); + return $this->_callEvent ('REGISTER_ACTION', $actiondata); } } Index: class.actionhandler.php =================================================================== RCS file: /cvsroot/phpcms-plugins/admin4phpCMS/include/class.actionhandler.php,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- class.actionhandler.php 26 May 2004 11:25:59 -0000 1.2 +++ class.actionhandler.php 30 May 2004 18:03:40 -0000 1.3 @@ -1,5 +1,48 @@ <?php +/** +* Actionhandler +* +* Der Actionhandler stellt die Verbindung zwischen einer Aktion und den darauf registrierten +* Funktionsaufrufen her. Gleichzeitig kümmert sich der Actionhandler um die Verwaltung der +* Objekte im Framework. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Martin Jahn <mj...@us...> +* @license GPL +* @copyright Copyright (c) 2004, Martin Jahn +* @version $$ +* @package admin4phpCMS +**/ +/* +* $Log$ +* Revision 1.3 2004/05/30 18:03:40 mjahn +* restructuring of some files +* +*/ +/** +* Actionhandler-Klasse +* +* Die Actionhandler-Klasse kapselt die komplette Verwaltung der Aktionen und die Objektverwaltung +* gegenüber der Framework-Klasse +* +* @package admin4phpCMS +* @see framework +* @see eventHandler +**/ class actionHandler { /** @@ -8,7 +51,7 @@ * @var array * @access private **/ - var $actions = array (); + var $_actions = array (); /** * Array mit den Relationen Klassenname -> Objekt @@ -19,25 +62,44 @@ * @var array * @access private **/ - var $objects = array (); + var $_objects = array (); + /** + * Konstruktor der Actionhandler-Klasse + * + * @ignore + **/ function actionHandler () { return $this->__construct (); } + /** + * Konstruktor der Actionhandler-Klasse + * + * @ignore + **/ function __construct () { // register my own classname with a reference to $this - $this->objects['actionHandler'] =& $this; - $this->actions['doRegisterAction'] = array('actionHandler'=>'registerAction'); + $this->_objects['actionHandler'] =& $this; + $this->_actions['doRegisterAction'] = array('actionHandler'=>'registerAction'); } - function &action ($actionname, &$actiondata) { - if (!isset($this->actions[$actionname])) { + /** + * gewünschte Aktion ausführen + * + * Diese Funktion wird ausschlieÃlich über den Eventhandler aufgerufen. + * + * @param string $actionname Name der auszuführenden Aktion + * @param array $actiondata Daten für die Aktion + * @return boolean Erfolg oder MiÃerfolg + **/ + function action ($actionname, &$actiondata) { + if (!isset($this->_actions[$actionname])) { return false; } - reset ($this->actions[$actionname]); - foreach ($this->actions[$actionname] as $actionclass => $actionmethod ) { + reset ($this->_actions[$actionname]); + foreach ($this->_actions[$actionname] as $actionclass => $actionmethod ) { $object =& $this->__getInstance($actionclass); $object->{$actionmethod}($actiondata); } @@ -45,44 +107,79 @@ return true; } + /** + * Aktion auf eine Funktion registrieren + * + * Diese Funktion wird ausschlieÃlich über den Eventhandler aufgerufen. + * Die übergebene Methode $actiondata['method'] einer Klasse $actiondata['class'] + * wird auf die Aktion $actiondata['actionname'] registriert. + * + * @param array $actiondata Daten für die zu registrierende Aktion + **/ function ®isterAction (&$actiondata) { $actionname = $actiondata['actionname']; $actionclass = $actiondata['class']; $actionmethod = $actiondata['method']; - $this->actions[$actionname] = array ($actionclass=>$actionmethod); - return true; + if (isset ($this->_actions[$actionname])) { + $this->_actions[$actionname] = array_merge ($this->_actions[$actionname], array ($actionclass=>$actionmethod)); + } else { + $this->_actions[$actionname] = array ($actionclass=>$actionmethod); + } } + /** + * Methode zum Laden von zusätzlichen Modulen + * + * Diese Funktion wird ausschlieÃlich über den Eventhandler aufgerufen. + * Der Parameter $actiondata muà foglende Daten über das Modul bereit stellen. + * <ul> + * <li><b>filename</b> der Pfad zur Moduldatei (absoluter Pfad im Dateisystem)</li> + * <li><b>class</b> Name der Modulklasse</li> + * </ul> + * + * @param array $actiondata Daten über das zu ladende Modul + * @return boolean Erfolg oder MiÃerfolg + **/ function &loadModule (&$actiondata) { $modulefile = $actiondata['filename']; $moduleclass = $actiondata['class']; - if (isset ($this->objects[$moduleclass])) { + if (isset ($this->_objects[$moduleclass])) { return true; } if (!file_exists ($modulefile)) { $actiondata = array ('errortext'=>'Modul '.$moduleclass.' konnte nicht unter '.$modulefile.' geladen werden!', 'type'=>'abort'); - $this->objects['eventHandler']->event ('ERROR_ABORT', $actiondata); + $this->_objects['eventHandler']->event ('ERROR_NOTICE', $actiondata); return false; } - @require_once ($modulefile); + require_once ($modulefile); - $this->objects[$moduleclass] =& $this->__getInstance ($moduleclass); + $this->_objects[$moduleclass] =& $this->__getInstance ($moduleclass); return true; } + /** + * Objecthandler + * + * Diese Methode verwaltet Objekte von sämtlichen Modulen und gibt eine Referenz + * auf ein Objekt der gewünschten Klasse zurück. existiert noch kein solches Objekt, + * wird es angelegtm initialisiert und im Objektarray gespeichert + * + * @param string $classname Klasse des gewünschten Objektes + * @return mixed false bei MiÃerfolg, sonst Referenz auf ein Objekt der Klasse $classname + **/ function &__getInstance (&$classname) { - if (isset ($this->objects[$classname])) { - return $this->objects[$classname]; + if (isset ($this->_objects[$classname])) { + return $this->_objects[$classname]; } if (!class_exists($classname)) { $actiondata = array ('errortext'=>'Klasse '.$classname.' existiert nicht!', 'type'=>'abort'); - $this->objects['eventHandler']->event ('ERROR_ABORT', $actiondata); + $this->_objects['eventHandler']->event ('ERROR_ABORT', $actiondata); return false; } - $obj =& new $classname ($this->objects['eventHandler']); + $obj =& new $classname ($this->_objects['eventHandler']); $obj->init (); return $obj; } Index: class.framework.php =================================================================== RCS file: /cvsroot/phpcms-plugins/admin4phpCMS/include/class.framework.php,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- class.framework.php 28 May 2004 12:07:43 -0000 1.3 +++ class.framework.php 30 May 2004 18:03:40 -0000 1.4 @@ -1,54 +1,123 @@ <?php +/** +* Admin4phpCMS - modulare Administrationsoberfläche +* +* Diese Software ist ein modulares Framework für Module aller Art. +* Zweck der Software ist es, die Administration einer Website durch verschiedene +* Module für den Administrator so einfach wie möglich zu halten. +* +* Ein integriertes Benutzer- und Rechtemanagment sorgt für den ungehinderten Zugriff +* für den Administrator und verhindert, daà DAUs die Website abschieÃen. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Martin Jahn <mj...@us...> +* @license GPL +* @copyright Copyright (c) 2004, Martin Jahn +* @version $$ +* @package admin4phpCMS +**/ + +/* +* $Log$ +* Revision 1.4 2004/05/30 18:03:40 mjahn +* restructuring of some files +* +*/ + +/** +* Einbinden der notwendigen Dateien +**/ include_once (dirname(__FILE__).'/class.actionhandler.php'); include_once (dirname(__FILE__).'/class.eventhandler.php'); include_once (dirname(__FILE__).'/class.module.php'); +/** +* @package admin4phpCMS +**/ class framework { function run () { global $ACTION; $this->eventhandler =& new eventHandler (new actionHandler ()); + // register some necessary events and actions $actiondata = array ('actionname'=>'doLoadModule', 'class'=>'actionHandler', 'method'=>'loadModule'); $this->eventhandler->event ('REGISTER_ACTION', $actiondata); $actiondata = array ('eventname'=>'LOAD_MODULE', 'eventaction'=>'doLoadModule'); $this->eventhandler->event ('REGISTER_EVENT', $actiondata); + $actiondata = array ('eventname'=>'PARSE_PARAM', 'eventaction'=>'doParseParam'); + $this->eventhandler->event ('REGISTER_EVENT', $actiondata); + $actiondata = array ('eventname'=>'PARSE_MENU', 'eventaction'=>'doParseMenu'); + $this->eventhandler->event ('REGISTER_EVENT', $actiondata); + $actiondata = array ('eventname'=>'DISPLAY_GET_CONTENTS', 'eventaction'=>'doGetContents'); + $this->eventhandler->event ('REGISTER_EVENT', $actiondata); + $actiondata = array ('eventname'=>'DISPLAY', 'eventaction'=>'doDisplay'); + $this->eventhandler->event ('REGISTER_EVENT', $actiondata); - $configfile = realpath (dirname (__FILE__).'/../config.xml'); - + // load the configuration module + // this is done hardcoded because of the configuration module $actiondata = array ('filename'=>dirname(__FILE__).'/../modules/config/class.module_config.php', 'class'=>'module_config'); $this->eventhandler->event ('LOAD_MODULE', $actiondata); - $actiondata = array ('configfile'=>$configfile); + + // parse the configuration file + $actiondata = array (); $this->eventhandler->event ('CONFIG_READ', $actiondata); - $actiondata = array ('configfile'=>$configfile); + // get configuration data with the modules to load + $actiondata = array (); $this->eventhandler->event ('CONFIG_GET', $actiondata); - $this->config =& $actiondata['config']; + $config =& $actiondata['config']; + // load all the needed modules $moduledir = realpath (dirname (__FILE__).'/../modules/'); - - foreach ($this->config->children as $module) { + foreach ($config as $id=>$module) { + + // this is no module if ($module->name != 'module') { continue; } + // calculate the path to the module file $includefile = $moduledir.'/'.$module->attributes['id'].'/'.$module->attributes['include']; + + // load module $actiondata = array ('filename'=>$includefile, 'class'=>$module->attributes['class']); $this->eventhandler->event ('LOAD_MODULE', $actiondata); - } + // let the modules parse the URI-params $actiondata = array ('get'=>$_GET, 'post'=>$_POST, 'request'=>$_REQUEST); $this->eventhandler->event ('PARSE_PARAM', $actiondata); + // let the modules do their work + $actiondata = array (); + $this->eventhandler->event ('PROCESS', $actiondata); + + // get the menudata from the modules $actiondata = array (); $this->eventhandler->event ('PARSE_MENU', $actiondata); + // let the modules parse their output + $actiondata = array (); + $this->eventhandler->event ('DISPLAY_GET_CONTENTS', $actiondata); + + // let the modules print their output $actiondata = array (); $this->eventhandler->event ('DISPLAY', $actiondata); - - } } Index: class.eventhandler.php =================================================================== RCS file: /cvsroot/phpcms-plugins/admin4phpCMS/include/class.eventhandler.php,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- class.eventhandler.php 26 May 2004 11:25:59 -0000 1.2 +++ class.eventhandler.php 30 May 2004 18:03:40 -0000 1.3 @@ -1,40 +1,112 @@ <?php +/** +* Eventhandler +* +* Der Eventhandler stellt die Verbindung zwischen einem Event und der richtigen Aktion her. +* Damit ist eine sehr flexible Modularisierung des Frameworks möglich. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Martin Jahn <mj...@us...> +* @license GPL +* @copyright Copyright (c) 2004, Martin Jahn +* @version $$ +* @package admin4phpCMS +**/ +/* +* $Log$ +* Revision 1.3 2004/05/30 18:03:40 mjahn +* restructuring of some files +* +*/ +/** +* Eventhandler-Klasse +* +* Die Eventhandler-Klasse kapselt die Verwaltung der Events gegenüber dem Framework +* +* @see framework +* @see actionHandler +* @package admin4phpCMS +**/ class eventHandler { - var $events = array (); + var $_events = array (); - function eventHandler (&$actionhandler) { - return $this->__construct ($actionhandler); - } + /** + * Konstruktor + * + * @param actionhandler $actionhandler Referenz zum Actionhandler-Objekt + * @ignore + **/ + function eventHandler (&$actionhandler) { + return $this->__construct ($actionhandler); + } - function __construct (&$actionhandler) { - $this->actionHandler =& $actionhandler; - $this->events['REGISTER_ACTION'] = 'doRegisterAction'; - $this->events['REGISTER_EVENT'] = 'doRegisterEvent'; - $this->actionHandler->objects['eventHandler'] =& $this; - $actiondata = array ('actionname'=>'doRegisterEvent', 'class'=>'eventHandler', 'method'=>'registerEvent'); - return $this->event('REGISTER_ACTION', $actiondata); - } + /** + * Konstruktor + * + * @param actionhandler $actionhandler Referenz zum Actionhandler-Objekt + * @ignore + **/ + function __construct (&$actionhandler) { + $this->_actionHandler =& $actionhandler; + $this->_events['REGISTER_ACTION'] = 'doRegisterAction'; + $this->_events['REGISTER_EVENT'] = 'doRegisterEvent'; + $this->_actionHandler->_objects['eventHandler'] =& $this; + $actiondata = array ('actionname'=>'doRegisterEvent', 'class'=>'eventHandler', 'method'=>'registerEvent'); + return $this->event('REGISTER_ACTION', $actiondata); + } - function &event ($eventname, &$actiondata) { - echo '<p>Event: '.$eventname.'</p>'; - if (!isset($this->events[$eventname])) { - return false; - } + /** + * Die Eventfunktion dient zum Ausführen von Events + * + * @param string $eventname Name des auszulösenden Events + * @param array $actiondata Parameter für die zum Event gehörende Action + * @return boolean Erfolg oder MiÃerfolg + **/ + function &event ($eventname, &$actiondata) { + //echo '<p>Event: '.$eventname.'</p>'; + if (!isset($this->_events[$eventname])) { + return false; + } - $action = $this->events[$eventname]; - return $this->actionHandler->action($action, $actiondata); - } - - function ®isterEvent (&$actiondata) { - $eventname = $actiondata['eventname']; - $eventaction = $actiondata['eventaction']; - if (isset($this->events[$eventname])) { - return false; - } - $this->events[$eventname] = $eventaction; - } + $action = $this->_events[$eventname]; + return $this->_actionHandler->action($action, $actiondata); + } + + /** + * Registriert eine Action auf ein Event + * + * Funktionsparameter + * <ul> + * <li><b>string $actiondata['eventname']</b> Name des Events</li> + * <li><b>string $actionname['eventaction']</b> Name der zum Event gehörenden Aktion</li> + * </ul> + * + * @param array $actiondata Parameter für die zum Event gehörende Action + * @return boolean Erfolg oder MiÃerfolg + **/ + function ®isterEvent (&$actiondata) { + $eventname = $actiondata['eventname']; + $eventaction = $actiondata['eventaction']; + if (isset($this->_events[$eventname])) { + return false; + } + $this->_events[$eventname] = $eventaction; + } } ?> \ No newline at end of file |