예제 #1
0
 /**
  * 自动加载
  */
 public function load($className)
 {
     //优先使用映射集合
     if (isset(self::$_loadMapp[$className])) {
         return CLoader::import($className, self::$_loadMapp[$className]);
     } else {
         if (file_exists($path = APP_PATH . '/modules/' . CRoute::getInstance()->getModule() . '/controllers/' . $className . '.php')) {
             return CLoader::importFile($path);
         } else {
             if (file_exists($path = APP_PATH . '/modules/' . CRoute::getInstance()->getModule() . '/classes/' . $className . '.php')) {
                 return CLoader::importFile($path);
             } else {
                 if (file_exists($path = CODE_PATH . '/controllers/' . $className . '.php')) {
                     return CLoader::importFile($path);
                 } else {
                     if (file_exists($path = FRAME_PATH . '/components/' . $className . '.php')) {
                         return CLoader::importFile($path);
                     } else {
                         $list = array();
                         $importList = CConfig::getInstance()->load('IMPORT');
                         if (!empty($importList)) {
                             foreach ((array) $importList as $thisPath) {
                                 $list[] = APP_PATH . '/' . str_replace(array('.', '*'), array('/', ''), $thisPath);
                             }
                         }
                         //查询指定的加载目录
                         foreach ($list as $val) {
                             if (file_exists($path = $val . $className . '.php')) {
                                 return CLoader::importFile($path);
                             } else {
                                 if (false !== strpos($className, '_')) {
                                     //处理类名中的路径
                                     $path = str_replace('_', '/', $className);
                                     if (file_exists($path = trim($val, '/\\') . '/' . $path . '.php')) {
                                         return CLoader::importFile($path);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
예제 #2
0
 /**
  * 加载插件
  */
 public static function loadPlugin()
 {
     $loadPlugin = CConfig::getInstance()->load('LOAD_PLUGIN');
     $loadList = CConfig::getInstance()->load('LOAD_LIST');
     if (false === $loadPlugin) {
         return false;
     }
     $pluginPath = APP_PATH . '/plugins/';
     $confPath = CConfig::getInstance()->load('PLUGIN_PATH');
     if (null != $confPath) {
         $pluginPath = APP_PATH . '/' . trim($confPath) . '/';
     }
     //定义插件宏
     define('CPLUGIN_PATH', $pluginPath);
     $hooksFile = self::_getPathFile($pluginPath, $loadList);
     foreach ($hooksFile as $val) {
         $pluginRegisterFilePath = $pluginPath . $val . '/' . $val . '.php';
         if (!file_exists($pluginRegisterFilePath)) {
             self::$_failLoadPluginList[] = array('pluginName' => $val);
             continue;
         }
         CLoader::importFile($pluginRegisterFilePath);
         $thisPluginObject = new $val();
         $thisPluginReflection = new ReflectionClass($thisPluginObject);
         $isSubCPlugin = $thisPluginReflection->isSubclassOf('CPlugin');
         if (false == $isSubCPlugin) {
             self::$_failLoadPluginList[] = $val;
             continue;
         }
         $thisPluginObject->setHooks();
         $thisPluginData['pluginName'] = isset($thisPluginObject->pluginName) ? $thisPluginObject->pluginName : '';
         $thisPluginData['author'] = isset($thisPluginObject->author) ? $thisPluginObject->author : '';
         $thisPluginData['version'] = isset($thisPluginObject->version) ? $thisPluginObject->version : '';
         $thisPluginData['copyright'] = isset($thisPluginObject->copyright) ? $thisPluginObject->copyright : '';
         $thisPluginData['date'] = isset($thisPluginObject->date) ? $thisPluginObject->date : '';
         $thisPluginData['description'] = isset($thisPluginObject->description) ? $thisPluginObject->description : '';
         self::$_pluginList[] = $thisPluginData;
     }
 }
예제 #3
0
 /**
  * 构造
  */
 public function __construct($viewName)
 {
     $this->_viewName = $viewName;
     $viewConfigs = CConfig::getInstance()->load('TEMPLATE');
     if (!isset($viewConfigs[$viewName])) {
         trigger_error('[视图错误]使用配置中不存在的模板引擎:' . $viewName, E_USER_ERROR);
     }
     $thisViewConfig = $viewConfigs[$viewName];
     $templatePath = isset($thisViewConfig['TEMPLATE_PATH']) ? $thisViewConfig['TEMPLATE_PATH'] : '';
     $viewConfItem = isset($thisViewConfig['CONF_INFO']) ? $thisViewConfig['CONF_INFO'] : array();
     if (!file_exists($templatePath)) {
         trigger_error('[视图错误]未能找到指定模板引擎[' . $viewName . ']的主文件:' . $templatePath, E_USER_ERROR);
     }
     CLoader::importFile($templatePath);
     $viewObject = new $viewName();
     if ('smarty' == $viewName) {
         $viewObject->template_dir = $viewConfItem['template_dir'];
         //编译目录
         $compile_dir = $viewConfItem['compile_dir'];
         if (!is_dir($compile_dir)) {
             if (false == mkdir($compile_dir, true, 0755)) {
                 echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>[部署错误]CMyFrame无法创建缓存目录,请确定服务器权限';
                 exit;
             }
             chmod($compile_dir, 0777);
         }
         $viewObject->compile_dir = $compile_dir;
         //缓存目录
         $cache_dir = $viewConfItem['cache_dir'];
         if (!is_dir($cache_dir)) {
             if (false == mkdir($cache_dir, true, 0755)) {
                 echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>[部署错误]CMyFrame无法创建缓存目录,请确定服务器权限';
                 exit;
             }
             chmod($cache_dir, 0777);
         }
         $viewObject->cache_dir = $cache_dir;
         //分隔符
         $viewObject->left_delimiter = $viewConfItem['left_delimiter'];
         $viewObject->right_delimiter = $viewConfItem['right_delimiter'];
         //使用PHP语法
         $viewObject->allow_php_tag = $viewConfItem['allow_php_tag'];
         //缓冲
         $viewObject->caching = $viewConfItem['caching'];
         $viewObject->cache_lifetime = $viewConfItem['cache_lifetime'];
         //注册函数
         $viewObject->register_function('url', array('CRequest', 'createUrl'));
         $viewObject->register_function('PageInfo', array('CSmarty', 'showPageData'));
         $viewObject->register_function('substr', array('CSmarty', 'cn_substr'));
         $viewObject->register_function('sayTime', array('CSmarty', 'sayTime'));
         //注册块函数
         $viewObject->register_block('checkRight', array('CSmarty', 'checkRight'));
         //设置默认数据
         CSmarty::setInitData($viewObject);
     } else {
         //设置所有配置项
         foreach ((array) $viewConfItem as $key => $val) {
             $viewObject->{$key} = $val;
         }
     }
     //第一次获取视图时
     CHooks::callHooks(HOOKS_VIEW_GET, $viewObject);
     $this->_viewObject = $viewObject;
 }