/** * 构造函数 */ public function __construct($configName) { $configPath = CODE_PATH . '/configs/' . $configName . '.php'; if (!file_exists($configPath)) { echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>[部署错误]主配置文件不存在!'; exit; } $this->configName = $configName; $this->thisConfigData = CLoader::import($configName, $configPath); }
/** * 自动加载 */ 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); } } } } } } } } } }