コード例 #1
0
ファイル: Module.php プロジェクト: joestump/framework
 /**
  * Try loading a module at a given location
  *
  * @param   string  $module  Module name
  * @param   string  $file    File the class is in
  * @param   string  $class   Class name of the module
  * @return  mixed   Framework_Module instance on success,
  *                  PEAR_Error otherwise.
  */
 public static function tryModule($module, $file, $class)
 {
     if (!(include_once $file)) {
         throw new Framework_Exception('Module file not found: ' . $file, FRAMEWORK_MODULE_ERROR_INVALID_MODULE_FILE);
     }
     if (!class_exists($class)) {
         throw new Framework_Exception('Module class not found: ' . $module, FRAMEWORK_MODULE_ERROR_INVALID_MODULE_CLASS);
     }
     $instance = new $class();
     if (!Framework_Module::isValid($instance)) {
         throw new Framework_Exception('Invalid module class loaded', FRAMEWORK_MODULE_ERROR_INVALID_MODULE_CLASS);
     }
     $instance->moduleName = $module;
     return $instance;
 }
コード例 #2
0
ファイル: Module.php プロジェクト: shupp/Framework
 /**
  * Try loading a module at a given location
  *
  * @param   string  $module  Module name
  * @param   string  $file    File the class is in
  * @param   string  $class   Class name of the module
  * @return  mixed   Framework_Module instance on success,
  *                  PEAR_Error otherwise.
  */
 public static function &tryModule($module, $file, $class)
 {
     if (!(include_once $file)) {
         return PEAR::raiseError('Module file not found: ' . $file, FRAMEWORK_MODULE_ERROR_INVALID_MODULE_FILE);
     }
     if (!class_exists($class)) {
         return PEAR::raiseError('Module class not found: ' . $module, FRAMEWORK_MODULE_ERROR_INVALID_MODULE_CLASS);
     }
     try {
         $instance = new $class();
         if (!Framework_Module::isValid($instance)) {
             return PEAR::raiseError('Invalid module class loaded');
         }
     } catch (Framework_Exception $error) {
         return PEAR::raiseError($error->getMessage());
     }
     $instance->moduleName = $module;
     return $instance;
 }