think\Config::load PHP Метод

load() публичный статический Метод

加载配置文件(PHP格式)
public static load ( string $file, string $name = '', string $range = '' ) : mixed
$file string 配置文件名
$name string 配置名(如设置即表示二级配置)
$range string 作用域
Результат mixed
    public static function load($file, $name = '', $range = '')
    {
        $range = $range ?: self::$range;
        if (!isset(self::$config[$range])) {
            self::$config[$range] = [];
        }
        if (is_file($file)) {
            $type = pathinfo($file, PATHINFO_EXTENSION);
            if ('php' == $type) {
                return self::set(include $file, $name, $range);
            } elseif ('yaml' == $type && function_exists('yaml_parse_file')) {
                return self::set(yaml_parse_file($file), $name, $range);
            } else {
                return self::parse($file, $type, $name, $range);
            }
        } else {
            return self::$config[$range];
        }
    }

Usage Example

Пример #1
0
 protected function buildCacheContent($module)
 {
     $content = '';
     $path = realpath(APP_PATH . $module) . DS;
     // 加载模块配置
     $config = \think\Config::load(CONF_PATH . $module . 'config' . CONF_EXT);
     // 加载应用状态配置
     if ($module && $config['app_status']) {
         $config = \think\Config::load(CONF_PATH . $module . $config['app_status'] . CONF_EXT);
     }
     // 读取扩展配置文件
     if ($module && $config['extra_config_list']) {
         foreach ($config['extra_config_list'] as $name => $file) {
             $filename = CONF_PATH . $module . $file . CONF_EXT;
             \think\Config::load($filename, is_string($name) ? $name : pathinfo($filename, PATHINFO_FILENAME));
         }
     }
     // 加载别名文件
     if (is_file(CONF_PATH . $module . 'alias' . EXT)) {
         $content .= '\\think\\Loader::addClassMap(' . var_export(include CONF_PATH . $module . 'alias' . EXT, true) . ');' . PHP_EOL;
     }
     // 加载行为扩展文件
     if (is_file(CONF_PATH . $module . 'tags' . EXT)) {
         $content .= '\\think\\Hook::import(' . var_export(include CONF_PATH . $module . 'tags' . EXT, true) . ');' . PHP_EOL;
     }
     // 加载公共文件
     if (is_file($path . 'common' . EXT)) {
         $content .= substr(php_strip_whitespace($path . 'common' . EXT), 5) . PHP_EOL;
     }
     $content .= '\\think\\Config::set(' . var_export(\think\Config::get(), true) . ');';
     return $content;
 }
All Usage Examples Of think\Config::load