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

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                作用:類依賴及運行依賴注入 ## **vendor\psr\container\src\ContainerInterface.php ContainerInterface類** **get**($id); **has**($id); ## **vendor\topthink\framework\src\think\Container.php Container類** **getInstance**():static -- (靜態函數) ---- 獲取當前容器的實例(單例),new static 是指對象是實例化的那個類的對象,一般是App **setInstance**($instance): void -- (靜態函數) ---- 設置當前容器的實例,設置后getInstance會直接返回 **resolving**($abstract, Closure $callback = null): void -- 注冊一個容器對象回調 $abstract為回調函數名或者回調函數名稱 **pull**(string $abstract, array $vars = [], bool $newInstance = false):object --(靜態函數) -- 獲取容器中的對象實例 不存在則創建(返回make處理后的類對象) <span style="color:green">**get**</span>($abstract=類名或者標識):object -- 獲取容器中的對象實例 <span style="color:green">**has**</span>($name): bool -- 判斷容器中是否存在類及標識 **getAlias**(string $abstract): string -- 根據別名獲取真實類名 本質上是獲取bind屬性指定$abstract鍵的值,如果bind屬性容器中沒有$abstract鍵則直接返回$abstract,如若存在著返回bind屬性$abstract鍵的值,其中`if (is_string($bind))...`這段代碼是剔除閉包函數的 ``` $app=new \think\App(); //綁定類庫標識 綁定的類標識可以自己定義 推進好記憶的方便自己快速取出(只要不沖突)。 $app->bind('think\Caches', 'app\common\Caches'); echo $app->getAlias('think\Caches');// app\common\Cache //綁定回調函數到容器 $app->bind('sayHello', function ($name) { return 'hello,' . $name; }); $app->getAlias('sayHello');// sayHello 閉包原樣輸出參數 $stdclass= new \stdClass(); // 綁定類實例 $app->bind('stdclass', $stdclass); $app->getAlias('stdclass');// stdclass類實例是存放在instances屬性中的 bind屬性中并無此鍵值 所以原樣輸出參數 ``` ### <span style="color:blue">**bind**</span>($abstract, $concrete = null):this -- 綁定一個類、閉包、實例、接口、實現 到容器中類: $abstract 類標識、接口 ,$concrete 要綁定的類、閉包或者實例 將這些類、閉包等 統一放入數組類型的bind屬性中(如果第二個參數是實例化后的對象則放入數組類型的instances屬性中(對象容器)),第一個參數是鍵第二個參數是值 ~~~ //綁定類庫標識 綁定的類標識可以自己定義 推進好記憶的方便自己快速取出(只要不沖突)。 (new \think\App())->bind('think\Cache', 'app\common\Cache'); //綁定回調函數到容器 new \think\App()->bind('sayHello', function ($name) { return 'hello,' . $name; }); $cache = new think\Cache; // 綁定類實例 new \think\App()->bind('cache', $cache); ~~~ >[danger] 與instance的區別就是,instance只保存類實例到instances屬性容器中, 而bind不僅可以保存類實例到instances屬性容器中,還可以保存類、閉包等到bind屬性容器 **instance**(string $abstract, $instance):this -- 綁定一個類實例到容器 ``` //將類對象(實例化后的類)保存進$instances屬性 注意:這里的 new \think\App()->instance('wechat', new \think\Wechat() ); ``` ### <span style="color:blue">**make**</span>(string $abstract, array $vars = [], bool $newInstance = false) -- 創建類的實例 已經存在則直接獲取 返回的是指定類實例 實際上通過invokeFunction或者invokeClass方法利用反射類的反射原理執行并返回類結果 如果是類返回實例后還會調用invokeAfter方法執行容器回調 ``` $http = (new App())->make('http'); ``` **invokeFunction**($function, array $vars = []):mixed -- 執行函數或者閉包方法 支持參數調用 **invokeMethod**($method, array $vars = [], bool $accessible = false):mixed -- 調用反射執行類的方法 支持參數綁定 **invokeReflectMethod**($instance, $reflect, array $vars = []):mixed -- 調用反射執行類的方法 支持參數綁定 **invoke**($callable, array $vars = [], bool $accessible = false):mixed -- 調用反射執行callable 支持參數綁定 **invokeClass**(string $class, array $vars = []) -- 調用反射執行類的實例化 支持依賴注入 **bound**(string $abstract): bool -- 判斷容器中是否存在類及標識 **exists**(string $abstract): bool -- 判斷容器中是否存在對象實例 **delete**($name):void -- 刪除容器中的對象實例 **factory**(string $name, string $namespace = '', ...$args):mixed --(靜態函數)-- 創建工廠對象實例 **__set**($name, $value):設置一個不存在或不可訪問的屬性時調用bind方法 **__get**($name):獲取一個不存在或不可訪問的屬性時調用get方法 **__isset**($name): bool:當對不存在或不可訪問的屬性使用isset或者empty時調用exists方法 **__unset**($name):當對不存在或不可訪問的屬性使用unset時調用delete方法 ## **vendor\topthink\framework\src\think\App.php APP類** 常量: VERSION -- tp版本 __construct(string $rootPath = ''):App -- 架構方法 初始化應用 register($service, bool $force = false):Service|null -- 注冊服務 bootService($service):mixed -- 執行服務 getService($service):Service|null -- 獲取服務 debug(bool $debug = true):this -- 開啟應用調試模式 isDebug(): bool -- 是否為調試模式 setNamespace(string $namespace):this -- 設置應用命名空間 getNamespace(): string -- 獲取應用類庫命名空間 version(): string -- 獲取框架版本(返回VERSION常量的值) getRootPath(): string -- 獲取應用根目錄(app上一層) getBasePath(): string -- 獲取應用基礎目錄(默認app) getAppPath(): string -- 獲取當前應用目錄 setAppPath(string $path):void -- 設置應用目錄 getRuntimePath(): string -- 獲取應用運行時目錄 setRuntimePath(string $path): void -- 設置runtime目錄 getThinkPath(): string -- 獲取核心框架目錄 getConfigPath(): string -- 獲取應用配置目錄 getConfigExt(): string -- 獲取配置后綴 getBeginTime(): float -- 獲取應用開啟時間 getBeginMem(): int -- 獲取應用初始內存占用 initialize():this -- 初始化應用 initialized():bool -- 是否初始化過 loadLangPack($langset):void -- 加載語言包 boot(): void -- 引導應用 parseClass(string $layer, string $name): string -- 解析應用類的類名 runningInConsole():void -- 是否運行在命令行下 loadEvent(array $event): void load(): void -- (protected) 用于app內部loadLangPack和initialize等方法加載文件 debugModeInit(): void -- (protected) 調試模式設置 getDefaultRootPath(): string -- (protected) 獲取應用根目錄
                  <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>

                              哎呀哎呀视频在线观看