当前位置: 首页>>代码示例>>PHP>>正文


PHP Kurogo::addModuleLib方法代码示例

本文整理汇总了PHP中Kurogo::addModuleLib方法的典型用法代码示例。如果您正苦于以下问题:PHP Kurogo::addModuleLib方法的具体用法?PHP Kurogo::addModuleLib怎么用?PHP Kurogo::addModuleLib使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Kurogo的用法示例。


在下文中一共展示了Kurogo::addModuleLib方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: factory

 /**
  * Factory method. Used to instantiate a subclass
  * @param string $id, the module id to load
  * @param string $type, the type of module to load (web/api)
  */
 public static function factory($id, $type = null)
 {
     if ($id == 'kurogo') {
         set_exception_handler("exceptionHandlerForError");
     }
     if (!self::isValidModuleName($id)) {
         throw new KurogoException(Kurogo::getLocalizedString('ERROR_INVALID_MODULE'));
     }
     Kurogo::log(LOG_INFO, "Initializing {$type} module {$id}", 'module');
     $configModule = $id;
     $configStore = Kurogo::configStore();
     //attempt to load config/$id/module.ini
     if ($moduleData = $configStore->getOptionalSection('module', 'module', $configModule)) {
         $id = Kurogo::arrayVal($moduleData, 'id', $configModule);
     } else {
         throw new KurogoModuleNotFound(Kurogo::getLocalizedString('ERROR_MODULE_NOT_FOUND', $id));
     }
     // see if the class location has been cached
     if ($moduleFile = Kurogo::getCache(self::cacheKey($id, $type))) {
         $className = basename($moduleFile, '.php');
         include_once $moduleFile;
         $module = new $className();
         if (is_a($module, KurogoWebBridge::STUB_API_CLASS)) {
             $module->setID($id);
         }
         $module->setConfigModule($configModule);
         Kurogo::addModuleLib($id);
         return $module;
     }
     // when run without a type it will find either
     $classNames = array('web' => ucfirst($id) . 'WebModule', 'api' => ucfirst($id) . 'APIModule', 'shell' => ucfirst($id) . 'ShellModule');
     // if we specified a type, include only that type in the array
     if ($type) {
         if (isset($classNames[$type])) {
             $classNames = array($classNames[$type]);
         } else {
             throw new KurogoException("Invalid module type {$type}");
         }
     }
     // possible module paths.
     // 1. Site Folder SiteMODULEIDXXXModule
     // 2. Site Folder MODULEIDXXXModule
     // 3. Project folder MODULEIDXXXModule
     // Note: The PHP class name MUST be the basename of the file path.
     $modulePaths = array(SITE_MODULES_DIR . "/{$id}/Site%s.php", SITE_MODULES_DIR . "/{$id}/%s.php", SHARED_MODULES_DIR . "/{$id}/Site%s.php", SHARED_MODULES_DIR . "/{$id}/%s.php", MODULES_DIR . "/{$id}/%s.php");
     if ($type == 'api' && KurogoWebBridge::moduleHasMediaAssets($configModule)) {
         $modulePaths[] = LIB_DIR . '/' . KurogoWebBridge::STUB_API_CLASS . ".php";
     }
     //cycle module paths
     foreach ($modulePaths as $path) {
         $className = basename($path, '.php');
         //cycle class names to find a valid module
         foreach ($classNames as $class) {
             $className = sprintf($className, $class);
             $path = sprintf($path, $class);
             Kurogo::log(LOG_DEBUG, "Looking for {$path} for {$id}", 'module');
             // see if it exists
             $moduleFile = realpath_exists($path);
             if ($moduleFile && (include_once $moduleFile)) {
                 //found it
                 $info = new ReflectionClass($className);
                 if (!$info->isAbstract()) {
                     Kurogo::log(LOG_INFO, "Found {$moduleFile} for {$id}", 'module');
                     $module = new $className();
                     if (is_a($module, KurogoWebBridge::STUB_API_CLASS)) {
                         $module->setID($id);
                     }
                     $module->setConfigModule($configModule);
                     // cache the location of the class (which also includes the classname)
                     Kurogo::setCache(self::cacheKey($id, $type), $moduleFile);
                     Kurogo::addModuleLib($id);
                     return $module;
                 }
                 Kurogo::log(LOG_NOTICE, "{$class} found at {$moduleFile} is abstract and cannot be used for {$id}", 'module');
                 return false;
             }
         }
     }
     Kurogo::log(LOG_NOTICE, "No valid {$type} class found for module {$id}", 'module');
     throw new KurogoModuleNotFound(Kurogo::getLocalizedString('ERROR_MODULE_NOT_FOUND', $id));
 }
开发者ID:sponto,项目名称:Kurogo-Mobile-Web,代码行数:86,代码来源:Module.php

示例2: factory

 /**
  * Factory method. Used to instantiate a subclass
  * @param string $id, the module id to load
  * @param string $type, the type of module to load (web/api)
  */
 public static function factory($id, $type = null)
 {
     if ($id == 'error') {
         set_exception_handler("exceptionHandlerForError");
     }
     Kurogo::log(LOG_INFO, "Initializing {$type} module {$id}", 'module');
     $configModule = $id;
     //attempt to load config/$id/module.ini
     if ($config = ModuleConfigFile::factory($id, 'module', ModuleConfigFile::OPTION_DO_NOT_CREATE)) {
         //use the ID parameter if it's present, otherwise use the included id
         $id = $config->getOptionalVar('id', $id);
     } elseif (!Kurogo::getOptionalSiteVar('CREATE_DEFAULT_CONFIG', false, 'modules')) {
         Kurogo::log(LOG_ERR, "Module config file not found for module {$id}", 'module');
         throw new KurogoModuleNotFound(Kurogo::getLocalizedString('ERROR_MODULE_NOT_FOUND', $id));
     }
     // see if the class location has been cached
     if ($moduleFile = Kurogo::getCache(self::cacheKey($id, $type))) {
         $className = basename($moduleFile, '.php');
         include_once $moduleFile;
         $module = new $className();
         if (is_a($module, KurogoWebBridge::STUB_API_CLASS)) {
             $module->setID($id);
         }
         $module->setConfigModule($configModule);
         if ($config) {
             $module->setConfig('module', $config);
         }
         Kurogo::addModuleLib($id);
         return $module;
     }
     // when run without a type it will find either
     $classNames = array('web' => ucfirst($id) . 'WebModule', 'api' => ucfirst($id) . 'APIModule', 'shell' => ucfirst($id) . 'ShellModule');
     // if we specified a type, include only that type in the array
     if ($type) {
         if (isset($classNames[$type])) {
             $classNames = array($classNames[$type]);
         } else {
             throw new KurogoException("Invalid module type {$type}");
         }
     }
     // possible module paths.
     // 1. Site Folder SiteMODULEIDXXXModule
     // 2. Site Folder MODULEIDXXXModule
     // 3. Project folder MODULEIDXXXModule
     $modulePaths = array(SITE_MODULES_DIR . "/{$id}/Site%s.php" => "Site%s", SITE_MODULES_DIR . "/{$id}/%s.php" => "%s", MODULES_DIR . "/{$id}/%s.php" => "%s");
     if ($type == 'api' && KurogoWebBridge::moduleHasMediaAssets($configModule)) {
         $modulePaths[KurogoWebBridge::STUB_API_CLASS_FILE] = KurogoWebBridge::STUB_API_CLASS;
     }
     //cycle module paths
     foreach ($modulePaths as $path => $className) {
         //cycle class names to find a valid module
         foreach ($classNames as $class) {
             $className = sprintf($className, $class);
             $path = sprintf($path, $class);
             Kurogo::log(LOG_DEBUG, "Looking for {$path} for {$id}", 'module');
             // see if it exists
             $moduleFile = realpath_exists($path);
             if ($moduleFile && (include_once $moduleFile)) {
                 //found it
                 $info = new ReflectionClass($className);
                 if (!$info->isAbstract()) {
                     Kurogo::log(LOG_INFO, "Found {$moduleFile} for {$id}", 'module');
                     $module = new $className();
                     if (is_a($module, KurogoWebBridge::STUB_API_CLASS)) {
                         $module->setID($id);
                     }
                     $module->setConfigModule($configModule);
                     if ($config) {
                         $module->setConfig('module', $config);
                     }
                     // cache the location of the class (which also includes the classname)
                     Kurogo::setCache(self::cacheKey($id, $type), $moduleFile);
                     Kurogo::addModuleLib($id);
                     return $module;
                 }
                 Kurogo::log(LOG_NOTICE, "{$class} found at {$moduleFile} is abstract and cannot be used for {$id}", 'module');
                 return false;
             }
         }
     }
     Kurogo::log(LOG_ERR, "No valid class found for module {$id}", 'module');
     throw new KurogoModuleNotFound(Kurogo::getLocalizedString('ERROR_MODULE_NOT_FOUND', $id));
 }
开发者ID:nncsang,项目名称:Kurogo,代码行数:88,代码来源:Module.php


注:本文中的Kurogo::addModuleLib方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。