<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>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                [TOC] * * * * * ## 1 全局配置文件 /thinkphp/library/think/Config.php 配置項操作類 /thinkphp/convention.php 全局默認配置項 ## 2 全局配置入口分析 全局配置項目的分析入口在/thinkphp/start.php中, 默認情況下的運行模式是common模式 因此會加載/thinkphp/mode/common.php模式配置文件。 配置項操作類Config的加載是 ~~~ if (isset($mode['namespace'])) { Loader::addNamespace($mode['namespace']); } ~~~ 根據common.php模式配置文件可知 ~~~ 'namespace' => [ 'think' => LIB_PATH . 'think' . DS, 'behavior' => LIB_PATH . 'behavior' . DS, 'traits' => LIB_PATH . 'traits' . DS, APP_NAMESPACE => APP_PATH, ], ~~~ 自動注冊命名空間目錄到Loader加載器中,加載器的實現見 附:自動加載器 ~~~ if (isset($mode['config'])) { is_array($mode['config']) ? Config::set($mode['config']) : Config::load($mode['config']); } ~~~ 檢查模式是否設置了$mode['config'] 檢查$mode['config']是否是數組,數組的情況下調用Config::set()添加到全局配置,如果不是數組則默認為文件,使用Config::load()加載相應的配置文件到全局配置。 其中的$mode['config']為THINK_PATH . 'convention' . EXT, 因此會加載/thinkphp/convention.php文件作為配置文件 ## 2 配置控制類Config文件分析 ~~~ private static $config = []; private static $range = '_sys_'; ~~~ 靜態變量 $config 全局配置參數存儲 靜態變量 $range 配置參數作用域 ~~~~ public static function range($range) { self::$range = $range; if (!isset(self::$config[$range])) { self::$config[$range] = []; } } ~~~ range()設置配置參數的作用域 也就是靜態變量$range ~~~ public static function parse($config, $type = '', $range = '') { $range = $range ?: self::$range; if (empty($type)) { $type = pathinfo($config, PATHINFO_EXTENSION); } $class = (false === strpos($type, '\\')) ? '\\think\\config\\driver\\' . ucwords($type) : $type; self::set((new $class())->parse($config), '', $range); } ~~~ 調用\think\config\driver\下的配置解析器 框架默認包含兩種配置解析器 ini.php和xml.php ~~~ public static function load($file, $name = '', $range = '') { $range = $range ?: self::$range; if (!isset(self::$config[$range])) { self::$config[$range] = []; } APP_DEBUG && Log::record('[ CONFIG ] ' . $file, 'info'); return is_file($file) ? self::set(include $file, $name, $range) : self::$config[$range]; } ~~~ load() 加載配置文件, ~~~ public static function has($name, $range = '') { $range = $range ?: self::$range; $name = strtolower($name); if (!strpos($name, '.')) { return isset(self::$config[$range][$name]); } else { $name = explode('.', $name); return isset(self::$config[$range][$name[0]][$name[1]]); } } ~~~ has()檢查某個配置項是否存在 ~~~ public static function get($name = null, $range = '') { $range = $range ?: self::$range; if (empty($name) && isset(self::$config[$range])) { return self::$config[$range]; } $name = strtolower($name); if (!strpos($name, '.')) { if (isset($_ENV[ENV_PREFIX . $name])) { return $_ENV[ENV_PREFIX . $name]; } return isset(self::$config[$range][$name]) ? self::$config[$range][$name] : null; } else { $name = explode('.', $name); if (isset($_ENV[ENV_PREFIX . $name[0] . '_' . $name[1]])) { return $_ENV[ENV_PREFIX . $name[0] . '_' . $name[1]]; } return isset(self::$config[$range][$name[0]][$name[1]]) ? self::$config[$range][$name[0]][$name[1]] : null; } } ~~~ get() 獲取某個配置項的值 ~~~ public static function set($name, $value = null, $range = '') { $range = $range ?: self::$range; if (!isset(self::$config[$range])) { self::$config[$range] = []; } if (is_string($name)) { $name = strtolower($name); if (!strpos($name, '.')) { self::$config[$range][$name] = $value; } else { $name = explode('.', $name); self::$config[$range][$name[0]][$name[1]] = $value; } return; } elseif (is_array($name)) { $config = array_change_key_case($name); if (!empty($value)) { self::$config[$range][$value] = isset(self::$config[$range][$value]) ? array_merge(self::$config[$range][$value], $config) : self::$config[$range][$value] = $config; return self::$config[$range][$value]; } else { return self::$config[$range] = array_merge(self::$config[$range], $config); } } else { return self::$config[$range]; } } ~~~ set() 設置某個配置項的值 ~~~ public static function reset($range = '') { $range = $range ?: self::$range;true === $range ? self::$config = [] : self::$config[$range] = []; } ~~~ reset() 清空全局配置信息 ## 3 配置項conventtion.php文件分析 ~~~ return [ // 應用模式狀態 'app_status' => '', // 注冊的根命名空間 'root_namespace' => [], // 擴展配置文件 'extra_config_list' => ['database', 'route', 'validate', 'auto'], // 擴展函數文件 'extra_file_list' => [THINK_PATH . 'helper' . EXT], // 默認輸出類型 'default_return_type' => 'html', // 默認語言 'default_lang' => 'zh-cn', // response是否返回方式 'response_return' => false, // 默認AJAX 數據返回格式,可選JSON XML ... 'default_ajax_return' => 'JSON', // 默認JSONP格式返回的處理方法 'default_jsonp_handler' => 'jsonpReturn', // 默認JSONP處理方法 'var_jsonp_handler' => 'callback', // 默認時區 'default_timezone' => 'PRC', // 是否開啟多語言 'lang_switch_on' => false, // 支持的多語言列表 'lang_list' => ['zh-cn'], // 語言變量 'lang_detect_var' => 'lang', // 語言cookie變量 'lang_cookie_var' => 'think_lang', // 默認全局過濾方法 用逗號分隔多個 'default_filter' => '', // 默認模塊名 'default_module' => 'index', // 禁止訪問模塊 'deny_module_list' => [COMMON_MODULE, 'runtime'], // 默認控制器名 'default_controller' => 'Index', // 默認操作名 'default_action' => 'index', // 默認的空控制器名 'empty_controller' => 'Error', // 操作方法后綴 'action_suffix' => '', // PATHINFO變量名 用于兼容模式 'var_pathinfo' => 's', // 兼容PATH_INFO獲取 'pathinfo_fetch' => ['ORIG_PATH_INFO', 'REDIRECT_PATH_INFO', 'REDIRECT_URL'], // pathinfo分隔符 'pathinfo_depr' => '/', // 獲取當前頁面地址的系統變量 默認為REQUEST_URI 'url_request_uri' => 'REQUEST_URI', // 基礎URL路徑 'base_url' => $_SERVER["SCRIPT_NAME"], // URL偽靜態后綴 'url_html_suffix' => '.html', // URL普通方式參數 用于自動生成 'url_common_param' => false, //url禁止訪問的后綴 'url_deny_suffix' => 'ico|png|gif|jpg', // 是否開啟路由 'url_route_on' => true, // 是否強制使用路由 'url_route_must' => false, // URL模塊映射 'url_module_map' => [], // 域名部署 'url_domain_deploy' => false, // 域名根,如.thinkphp.cn 'url_domain_root' => '', // 是否自動轉換URL中的控制器名 'url_controller_convert' => true, // 是否自動轉換URL中的操作名 'url_action_convert' => true, // 默認跳轉頁面對應的模板文件 'dispatch_success_tmpl' => THINK_PATH . 'tpl' . DS . 'dispatch_jump.tpl', 'dispatch_error_tmpl' => THINK_PATH . 'tpl' . DS . 'dispatch_jump.tpl', // 默認的模板引擎 'template_engine' => 'Think', // 異常頁面的模板文件 'exception_tmpl' => THINK_PATH . 'tpl' . DS . 'think_exception.tpl', // 異常處理忽略的錯誤類型,支持PHP所有的錯誤級別常量,多個級別可以用|運算法 // 參考:http://php.net/manual/en/errorfunc.constants.php 'exception_ignore_type' => 0, // 錯誤顯示信息,非調試模式有效 'error_message' => '頁面錯誤!請稍后再試~', // 錯誤定向頁面 'error_page' => '', // 顯示錯誤信息 'show_error_msg' => false, 'log' => [ 'type' => 'File', // 支持 file socket trace sae 'path' => LOG_PATH, ], 'cache' => [ 'type' => 'File', 'path' => CACHE_PATH, 'prefix' => '', 'expire' => 0, ], // 是否使用session 'use_session' => true, 'session' => [ 'id' => '', 'var_session_id' => '', // SESSION_ID的提交變量,解決flash上傳跨域 'prefix' => 'think', 'type' => '', 'auto_start' => true, ], 'db_fields_strict' => true, 'database' => [ // 數據庫類型 'type' => 'mysql', // 數據庫連接DSN配置 'dsn' => '', // 服務器地址 'hostname' => 'localhost', // 數據庫名 'database' => '', // 數據庫用戶名 'username' => 'root', // 數據庫密碼 'password' => '', // 數據庫連接端口 'hostport' => '', // 數據庫連接參數 'params' => [], // 數據庫編碼默認采用utf8 'charset' => 'utf8', // 數據庫表前綴 'prefix' => '', // 數據庫調試模式 'debug' => false, // 數據庫部署方式:0 集中式(單一服務器),1 分布式(主從服務器) 'deploy' => 0, // 數據庫讀寫是否分離 主從式有效 'rw_separate' => false, // 讀寫分離后 主服務器數量 'master_num' => 1, // 指定從服務器序號 'slave_no' => '', ], ]; ~~~ 返回一個數組作為全局默認配置 ## 4 總結 經過啟動流程的/thinkphp/start.php。 會根據系統的運行模式common.php配置文件, 自動加載配置操作類Class Config, 并加載框架的默認全局配置文件/thinkphp/convention.php. convention.php 包括了全局默認配置項 Config.php 定義了配置項操作和配置參數的存儲地方靜態變量$config, 包含基本的set() get() has() load() parse() reset()操作 **可以看做普通的類的屬性操作擴展實現** convention.php 包含了全局默認配置. ## 5全局變量(base.php),模式配置(common.php),全局配置(convention.php)比較 | 文件 |加載位置與順序 |定義方式 |定義內容 | | -- | -- | -- | -- | | base.php | start.php中,第一個加載 | define | 配置全局信息 | | common.php |start.php中,第二個加載 | array | 配置運行環境信息 | | convention.php |common.php中,第三個加載 |array |配置框架組織信息 | 全局配置文件涉及框架運行的各個方面,其使用見使用范例的 框架配置
                  <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>

                              哎呀哎呀视频在线观看