From 24173926fa9e13ef5c3509645fca69e5304b0068 Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Tue, 19 Aug 2008 23:19:19 +0200 Subject: [PATCH] Add PlModule::load() that load a module-specific include. Before: require_once dirname(__FILE__) . '/modulename/file.inc.php'; After: $this->load('file.inc.php'); Signed-off-by: Florent Bruneau --- classes/plmodule.php | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/classes/plmodule.php b/classes/plmodule.php index 9d5dc9b..ec1e5f0 100644 --- a/classes/plmodule.php +++ b/classes/plmodule.php @@ -21,7 +21,17 @@ abstract class PLModule { - abstract function handlers(); + /** Path of the includes of the module + * Internal use only. + */ + private $modIncludePath; + + /** Return an array associating pathes to the corresponding hook. + * array( '/my/path' => make_hook(...), + * ...); + * @ref make_hook + */ + abstract public function handlers(); /** Register a hook * @param fun name of the handler (the exact name will be handler_$fun) @@ -46,20 +56,30 @@ abstract class PLModule 'type' => $type); } + /** Include a 'module-specific' file. + * Module specific includes must be in the in the path modules/{modulename}. + */ + public function load($file) + { + require_once $this->modIncludePath . $file; + } + /* static functions */ public static function factory($modname) { global $globals; if ($modname == 'core') { - $mod_path = $globals->spoolroot . '/core/modules/' . $modname . '.php'; + $mod_path = $globals->spoolroot . '/core/modules/' . $modname; } else { - $mod_path = $globals->spoolroot . '/modules/' . $modname . '.php'; + $mod_path = $globals->spoolroot . '/modules/' . $modname; } $class = ucfirst($modname) . 'Module'; - require_once $mod_path; - return new $class(); + require_once $mod_path . '.php'; + $module = new $class(); + $module->modIncludePath = $mod_path . '/'; + return $module; } } -- 2.1.4