/** * Loads the module filename and instanciates the module with the given name, eg. UserCountry * Do NOT give the class name ie. Core_UserCountry, but give the module name ie. UserCountry * * @param Core_Module $moduleName */ public function loadModule($moduleName) { if (isset($this->loadedModules[$moduleName])) { return $this->loadedModules[$moduleName]; } $moduleFileName = $moduleName . '/Module.php'; $moduleClassName = 'Module_' . $moduleName . '_Module'; if (!Core_Common::isValidFilename($moduleName)) { throw new Exception("The module filename '{$moduleFileName}' is not a valid filename"); } $path = INCLUDE_PATH . '/Module/' . $moduleFileName; if (!file_exists($path)) { throw new Exception("Unable to load module '{$moduleName}' because '{$path}' couldn't be found.\n\t\t\tYou can manually uninstall the module by removing the line <code>Modules[] = {$moduleName}</code> from the Core config file."); } // Don't remove this. // Our autoloader can't find Module/ModuleName/Module.php require_once $path; // prefixed by CORE_INCLUDE_PATH if (!class_exists($moduleClassName, false)) { throw new Exception("The class {$moduleClassName} couldn't be found in the file '{$path}'"); } $newModule = new $moduleClassName(); if (!$newModule instanceof Core_Module) { throw new Exception("The module {$moduleClassName} in the file {$path} must inherit from Core_Module."); } return $newModule; }