<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                [TOC] * * * * * # 1 配置 >>配置,通常指的是存儲框架運行基礎信息的文件。 >框架啟動的時候,加載配置文件,解析為框架運行基礎信息。 >應用啟動的時候,也會加載應用相應的配置文件,解析為應用運行基礎信息。 >相對于緩存(Cache)。配置的作用周期只在當前請求。緩存則可以跨請求使用。 # 2 配置操作 ## 2-1 配置文件加載 ### Config::load() >>加載配置文件 ~~~ 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::parse($file, $type, $name, $range); } else { return self::set(include $file, $name, $range); } } else { return self::$config[$range]; } } ~~~ ### Config::parse() >>解析配置文件的內容, >根據不同類型的配置文件,創建不同的配置解析器。 >配置解析器的實現在(\Config\driver\)目錄下,tp5內置了Ini,Json,xml等類型解析。 ~~~ public static function parse($config, $type = '', $name = '', $range = '') { $range = $range ?: self::$range; if (empty($type)) { $type = pathinfo($config, PATHINFO_EXTENSION); } $class = false !== strpos($type, '\\') ? $type : '\\think\\config\\driver\\' . ucwords($type); return self::set((new $class())->parse($config), $name, $range); } ~~~ ## 2-2 配置內容操作 ### Config::get() >>獲取配置內容 ~~~ public static function get($name = null, $range = '') { $range = $range ?: self::$range; // 無參數時獲取所有 if (empty($name) && isset(self::$config[$range])) { return self::$config[$range]; } if (!strpos($name, '.')) { $name = strtolower($name); return isset(self::$config[$range][$name]) ? self::$config[$range][$name] : null; } else { // 二維數組設置和獲取支持 $name = explode('.', $name); $name[0] = strtolower($name[0]); return isset(self::$config[$range][$name[0]][$name[1]]) ? self::$config[$range][$name[0]][$name[1]] : null; } } ~~~ ### Config::set() >>設置配置內容 ~~~ public static function set($name, $value = null, $range = '') { $range = $range ?: self::$range; if (!isset(self::$config[$range])) { self::$config[$range] = []; } if (is_string($name)) { if (!strpos($name, '.')) { self::$config[$range][strtolower($name)] = $value; } else { // 二維數組設置和獲取支持 $name = explode('.', $name); self::$config[$range][strtolower($name[0])][$name[1]] = $value; } return; } elseif (is_array($name)) { // 批量設置 if (!empty($value)) { self::$config[$range][$value] = isset(self::$config[$range][$value]) ? array_merge(self::$config[$range][$value], $name) : self::$config[$range][$value] = $name; return self::$config[$range][$value]; } else { return self::$config[$range] = array_merge(self::$config[$range], array_change_key_case($name)); } } else { // 為空直接返回 已有配置 return self::$config[$range]; } } ~~~ ### Config::reset() >>重置配置為空 ~~~ public static function reset($range = '') { $range = $range ?: self::$range; if (true === $range) { self::$config = []; } else { self::$config[$range] = []; } } ~~~ ### Config::has() >>檢查配置是否存在 ~~~ public static function has($name, $range = '') { $range = $range ?: self::$range; if (!strpos($name, '.')) { return isset(self::$config[$range][strtolower($name)]); } else { // 二維數組設置和獲取支持 $name = explode('.', $name); return isset(self::$config[$range][strtolower($name[0])][$name[1]]); } } ~~~ ## 2-3 配置作用域 >>可以修改配置作用域。實現配置的特定場景使用 ### Config::range() >>修改當前配置作用域 ~~~ public static function range($range) { self::$range = $range; if (!isset(self::$config[$range])) { self::$config[$range] = []; } } ~~~ # 3 內置配置解析器 ## 3-1 Ini配置解析器 ### $iniconfig->parse() >>解析Ini配置文件 ~~~ public function parse($config) { if (is_file($config)) { return parse_ini_file($config, true); } else { return parse_ini_string($config, true); } } ~~~ ## 3-2 Json配置解析器 ### $jsonconfig->parse() >>解析Json配置文件 ~~~ public function parse($config) { if (is_file($config)) { $config = file_get_contents($config); } $result = json_decode($config, true); return $result; } ~~~ ## 3-3 Xml配置解析器 ### $xmlconfig->parse() >>解析Xml配置文件 ~~~ public function parse($config) { if (is_file($config)) { $content = simplexml_load_file($config); } else { $content = simplexml_load_string($config); } $result = (array) $content; foreach ($result as $key => $val) { if (is_object($val)) { $result[$key] = (array) $val; } } return $result; } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看