/** * 重新加载类库 * */ protected static function reload_all_libraries() { # 加载类库 $lib_config = self::$core_config['libraries']; # 重置 self::$include_path['library'] = array(); foreach (array('autoload', 'cli', 'admin', 'debug', 'rest') as $type) { if (!isset($lib_config[$type]) || !$lib_config[$type]) { continue; } if ($type == 'cli') { if (!IS_DEBUG) { continue; } } else { if ($type == 'admin') { if (!IS_ADMIN_MODE) { continue; } } else { if ($type == 'rest') { if (!IS_REST_MODE) { continue; } } else { if ($type == 'debug') { if (!IS_DEBUG) { continue; } } } } } $libs = array_reverse((array) $lib_config[$type]); foreach ($libs as $lib) { self::_add_include_path_lib($lib); } } # 处理 library 的config $config_files = array(); self::get_config_file_by_path($config_files, self::$include_path['project'], true); self::get_config_file_by_path($config_files, self::$include_path['team-library'], true); self::get_config_file_by_path($config_files, self::$include_path['library'], false); self::get_config_file_by_path($config_files, self::$include_path['core'], false); if ($config_files) { # 反向排序,从最后一个开始导入 $config_files = array_reverse($config_files); # 导入config self::$config = self::$core_config; # 移除特殊的key unset(self::$config['core']); unset(self::$config['projects']); # 载入config __include_config_file(self::$config, $config_files); } }
/** * 获取指定key的配置 * * 若不传key,则返回Core_Config对象,可获取动态配置,例如Core::config()->get(); * * @param string $key * @param mixed $default 默认值 * @return array|string|null|Config */ public static function config($key = null, $default = null) { if (null === $key) { return Core::factory('Config'); } $c = explode('.', $key); $config_name = array_shift($c); if (strtolower($config_name) === 'core') { $tmp = Core::$core_config; } else { /** * 记录加载过的配置 */ static $loaded_config = array(); if (isset($loaded_config[Core::$project][$config_name])) { if (isset(Core::$config[$config_name])) { $tmp = Core::$config[$config_name]; } else { return $default; } } else { # 标记为已经加载 $loaded_config[Core::$project][$config_name] = true; $all_config_files = self::get_config_files(); if (isset($all_config_files[$config_name])) { # 加载配置文件 $config_files = $all_config_files[$config_name]; #逆向排序,使得最高优先级的文件最后一个加载 krsort($config_files); if (isset(Core::$config[$config_name])) { $config = Core::$config[$config_name]; } else { $config = array(); } # 读取配置 __include_config_file($config, $config_files); # 将新的配置更新到 Core::$config 中 $tmp = Core::$config[$config_name] = $config; } elseif (isset(Core::$config[$config_name])) { $tmp = Core::$config[$config_name]; } else { return $default; } } } if ($c) { foreach ($c as $i) { if (!isset($tmp[$i])) { return $default; } $tmp = $tmp[$i]; } } return $tmp; }