<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、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                https://www.cnblogs.com/liangphp/p/12018993.html 小亮最近在翻thinkphp和laravel手冊,發現其中大量使用容器概念。那么什么是容器呢?字面意思理解為裝東西的器皿。那么裝的是什么呢?裝的是類實例化的對象。為什么要這么做呢?第一點使用對象方便,第二點解耦。下面一個例子簡單的貫穿了框架中使用的容器服務,其中涉及一些知識如依賴注入、函數閉包(Closure)、匿名函數、回調函數call\_user\_func\_array、控制反轉(Ioc)等等。留著自己復習,也供大家參考。 [![復制代碼](https://common.cnblogs.com/images/copycode.gif)](javascript:void(0); "復制代碼") ~~~ <?php //創建一個類 class Shenyang { private $area;//地區 public function __construct(IArea $area) { $this->area=$area; $this->area->myarea(); } } //定義地區接口,來實現多態。方便實例化各個地區 interface IArea { public function myarea(); } class Huanggu implements IArea { public function myarea() { echo "我是皇姑區"; } } class Shenhe implements IArea { public function myarea() { echo "我是沈河區"; } } class Container { public $bind=[];//綁定實例名 public $instance=[];//實例數組 //綁定方法,第一個參數是實例名,第二個參數是個閉包 public function bind($abstract,$closure) { if($closure instanceof Closure){ $this->bind[$abstract]=$closure; }else{ $this->instance[$abstract]=$closure; } } //從容器中取出實例,第一個參數是實例名,第二參數是實例依賴的對象 public function make($abstract,$parameters=[]) { if(isset($this->instance[$abstract])){ return $this->instance[$abstract]; }else{ //將容器對象帶走 array_unshift($parameters,$this); //執行閉包 return call_user_func_array($this->bind[$abstract],$parameters); } } } //實例化容器 $container=new Container(); //將類綁定 $container->bind('huanggu',function (){return new Huanggu();}); //將類綁定的同時,通過構造方法依賴注入 $container->bind('shenyang',function ($container,$module){ return new Shenyang($container->make($module)); }); //從容器中取出 $container->make('shenyang',['huanggu']); ~~~ [![復制代碼](https://common.cnblogs.com/images/copycode.gif)](javascript:void(0); "復制代碼") ThinkPHP容器之初步解析 https://www.php.cn/phpkj/thinkphp/461075.html
                  <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>

                              哎呀哎呀视频在线观看