示例#1
0
 /**
  *
  */
 static function load($module, $optional = false)
 {
     // Check if the path is globbed
     if (strpos($module, '*') == strlen($module) - 1) {
         $path = self::_mangleModulePath($module);
         Console::debugEx(LOG_EXTENDED, __CLASS__, "Looking for modules matching %s from %s", $module, $path);
         $f = glob($path);
         sort($f);
         $failed = false;
         foreach ($f as $file) {
             if (!ModuleManager::load(str_replace('*', basename($file, '.php'), $module))) {
                 $failed = true;
             }
         }
         return !$failed;
     }
     // Check if the module is already loaded
     if (ModuleManager::has($module)) {
         logger::debug("Already loaded %s.", $module);
         return true;
     }
     // Otherwise mangle the path
     $path = self::_mangleModulePath($module);
     /*
      if (file_exists(APP_PATH.$modpath)) {
      $path = APP_PATH.$modpath;
      } elseif (file_exists(SYS_PATH.$modpath)) {
      $path = SYS_PATH.$modpath;
      } else {
      $path = null;
      }
     */
     if ($path) {
         if (file_exists(basename($path, '.php') . '.class.php')) {
             $path = basename($path, '.php') . '.class.php';
         }
         if (file_exists($path)) {
             self::$_lastmodule = $module;
             Console::debugEx(LOG_BASIC, __CLASS__, "Loading %s (%s).", $module, str_replace(BASE_PATH, '', $path));
             try {
                 ModuleManager::$_modules[strtolower($module)] = array();
                 ModuleManager::$_order[] = strtolower($module);
                 // Console::debugEx(LOG_DEBUG2,__CLASS__,"  path = %s", $path);
                 require $path;
                 array_pop(ModuleManager::$_order);
             } catch (ModuleException $e) {
                 Console::debugEx(LOG_BASIC, __CLASS__, "Exception loading %s!", $module);
                 throw $e;
                 return false;
             }
             return true;
         } else {
             throw new ModuleException("Could not load module " . $module . ": Path not found");
             return false;
         }
     } else {
         Console::debugEx(LOG_BASIC, __CLASS__, "Failed to load %s.", $module);
         return false;
     }
 }