04-14-2009, 02:25 PM
|
#7 (permalink)
|
|
The Addict
Join Date: Nov 2007
Location: the Netherlands
Posts: 281
Thanks: 2
|
I use it to locate and validate a module:
PHP Code:
/** * Loads a module * * @param string $szModuleName */ public function LoadModule($szModuleName) { /* * A module is made with a folder in the /modules directory, * from that folder the index.php folder is read */ $szModulePath = CONF_MAIN_PATH . '/modules/' . basename($szModuleName) . '/index.php'; if(file_exists($szModulePath)) { require_once($szModulePath); $moduleReflection = new ReflectionClass($szModuleName); // Get main method if($moduleReflection->implementsInterface('IModule')) { $moduleMainMethod = $moduleReflection->getMethod('Main'); // method is static, invoke if($moduleMainMethod->isStatic()) { $moduleMainMethod->invoke(null); } else { $moduleInstance = $moduleReflection->newInstance(); $moduleMainMethod->invoke($moduleInstance); } } else { throw new Exception('File is not a valid module'); } } else { // File does not exist throw new Exception('Could not find module.'); } }
__________________
Nunchaku! Who doesn't like martial arts? =)
|
|
|