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

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                [TOC] * * * * * ## 1 自動加載器實例化源代碼(thinkphp/library/think/Loader) ~~~ public static function table($name = '', array $options = []) { static $_model = []; if (strpos($name, ':')) { list($class, $name) = explode(':', $name); } else { $class = 'think\\Model'; } $guid = $name . '_' . $class; if (!isset($_model[$guid])) { $_model[$guid] = new $class($name, $options); } return $_model[$guid]; } public static function model($name = '', $layer = MODEL_LAYER) { if (empty($name)) { return new Model; } static $_model = []; if (isset($_model[$name . $layer])) { return $_model[$name . $layer]; } if (strpos($name, '/')) { list($module, $name) = explode('/', $name, 2); } else { $module = APP_MULTI_MODULE ? MODULE_NAME : ''; } $class = self::parseClass($module, $layer, $name); $name = basename($name); if (class_exists($class)) { $model = new $class($name); } else { $class = str_replace('\\' . $module . '\\', '\\' . COMMON_MODULE . '\\', $class); if (class_exists($class)) { $model = new $class($name); } else { Log::record('實例化不存在的類:' . $class, 'notice'); $model = new Model($name); } } $_model[$name . $layer] = $model; return $model; } public static function controller($name, $layer = '', $empty = '') { static $_instance = []; $layer = $layer ?: CONTROLLER_LAYER; if (isset($_instance[$name . $layer])) { return $_instance[$name . $layer]; } if (strpos($name, '/')) { list($module, $name) = explode('/', $name); } else { $module = APP_MULTI_MODULE ? MODULE_NAME : ''; } $class = self::parseClass($module, $layer, $name); if (class_exists($class)) { $action = new $class; $_instance[$name . $layer] = $action; return $action; } elseif ($empty && class_exists($emptyClass = self::parseClass($module, $layer, $empty))) { return new $emptyClass; } else { throw new Exception('class [ ' . $class . ' ] not exists', 10001); } } public static function db($config = []) { return Db::connect($config); } public static function action($url, $vars = [], $layer = CONTROLLER_LAYER) { $info = pathinfo($url); $action = $info['basename']; $module = '.' != $info['dirname'] ? $info['dirname'] : CONTROLLER_NAME; $class = self::controller($module, $layer); if ($class) { if (is_scalar($vars)) { if (strpos($vars, '=')) { parse_str($vars, $vars); } else { $vars = [$vars]; } } return App::invokeMethod([$class, $action . Config::get('action_suffix')], $vars); } } public static function instance($class, $method = '') { static $_instance = []; $identify = $class . $method; if (!isset($_instance[$identify])) { if (class_exists($class)) { $o = new $class(); if (!empty($method) && method_exists($o, $method)) { $_instance[$identify] = call_user_func_array([ & $o, $method], []); } else { $_instance[$identify] = $o; } } else { throw new Exception('class not exist :' . $class, 10007); } } return $_instance[$identify]; } public static function parseName($name, $type = 0) { if ($type) { return ucfirst(preg_replace_callback('/_([a-zA-Z])/', function ($match) {return strtoupper($match[1]);}, $name)); } else { return strtolower(trim(preg_replace("/[A-Z]/", "_\\0", $name), "_")); } } public static function parseClass($module, $layer, $name) { $name = str_replace(['/', '.'], '\\', $name); $array = explode('\\', $name); $class = self::parseName(array_pop($array), 1); $path = $array ? implode('\\', $array) . '\\' : ''; return APP_NAMESPACE . '\\' . (APP_MULTI_MODULE ? $module . '\\' : '') . $layer . '\\' . $path . $class; } ~~~ * * * * * ## 2 分析 1 table($name='',arrat $option) 實例化以$name為名字的Model對象 `public static function table($name = '', array $options = []){}` 創建一個靜態變量數組$_model緩存所有實例化的Model對象。 * * * * * 2 model($name='',$layer) 實例化以$name為名字的Model對象 `public static function model($name = '', $layer = MODEL_LAYER){}` 同上 使用靜態變量數組$_model緩存 對比table()與model() table()創建無模型文件的的Model。直接對應數據表 model()創建有模型文件關聯的Model。對應模型的子類 * * * * * 3 controller() 實例化以$name為名字的控制器 `public static function controller($name, $layer = '', $empty = ''){}` 創建一個靜態變量數組$_instance緩存所有實例化的控制對象 * * * * * 4 db($config=[]) 根據配置創建數據庫連接對象。 `public static function db($config = []){}` * * * * * 5action() 遠程調用url對應的控制器方法 `public static function action($url, $vars = [], $layer = CONTROLLER_LAYER){}` 使用self::controller()創建url對應控制器 使用App::invokeMethod()調用對應控制的action方法 * * * * * 6 instance() 創建$class對應的類,如果存在$method,則調用對象的$method `public static function instance($class, $method = ''){}` 使用$_instance 緩存創建的對象 * * * * * 7parseName() 轉換字符串命名風格 `public static function parseName($name, $type = 0){}` * * * * * 8 parseClass() 解析類名到系統中命名空間模塊分層下的目錄類名文件 `public static function parseClass($module, $layer, $name){}` * * * * * * * * * * ## 3 使用方法 TODO ## 4 總結 自動加載器的實例化方法用來實例化對象并緩存。
                  <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>

                              哎呀哎呀视频在线观看