久久久久在线观看_又色又爽又黄的免费视频播放_一区中文字幕_日韩电影在线播放

今日頭條 焦點資訊 營銷之道 企業報道 淘寶運營 網站建設 軟件開發 400電話
  當前位置: 首頁 » 資訊 » 軟件開發 » 正文

Laravel 5.5) 加載過程instance方法

放大字體  縮小字體 發布日期:2018-02-20  來源:企業800網  作者:新格網  瀏覽次數:307  【去百度看看】
在bootstrap/app.php

$app = new Illuminate\Foundation\Application(    realpath(__DIR__.'/../')
);

實例化 vendor/laravel/framework/src/Illuminate/Foundation/Application.php類 該類的魔術方法

    public function __construct($basePath = null)
    {        
        if ($basePath) {            $this->setbasePath($basePath);
        }        
        $this->registerbaseBindings();        
        $this->registerbaseServiceProviders();        
        $this->registerCoreContainerAliases();
    }

查看注冊 app 和container到 instances數組中

    protected function registerbaseBindings()
    {        static::setInstance($this);        
        $this->instance('app', $this);        
        $this->instance(Container::class, $this);
    }


查看今天主要的方法 instance

流程圖

 public function instance($abstract, $instance)
    {        
        $this->removeAbstractAlias($abstract);        
        $isBound = $this->bound($abstract);        
        unset($this->aliases[$abstract]);        // We'll check to determine if this type has been bound before, and if it has
        // we will fire the rebound callbacks registered with the container and it
        // can be updated with consuming classes that have gotten resolved here.
        
        $this->instances[$abstract] = $instance;        
        if ($isBound) {            $this->rebound($abstract);
        }
    }

第一個方法 removeAbstractAlias

    
    protected function removeAbstractAlias($searched)
    {        
        if (! isset($this->aliases[$searched])) {            return;
        }        
        foreach ($this->abstractAliases as $abstract => $aliases) {            foreach ($aliases as $index => $alias) {                if ($alias == $searched) {                    unset($this->abstractAliases[$abstract][$index]);
                }
            }
        }
    }

第二個方法: bound

    
    public function bound($abstract)
    {        return isset($this->bindings[$abstract]) ||               isset($this->instances[$abstract]) ||               $this->isAlias($abstract);
    }

第三個方法: rebound

 
    protected function rebound($abstract)
    {        
        $instance = $this->make($abstract);        
        foreach ($this->getReboundCallbacks($abstract) as $callback) {            call_user_func($callback, $this, $instance);
        }
    }

以上就是Laravel 5.5) 加載過程instance方法的詳細內容,更多請關注php中文網其它相關文章!

 
 
[ 資訊搜索 ]  [ 加入收藏 ]  [ 告訴好友 ]  [ 打印本文 ]  [ 違規舉報 ]  [ 關閉窗口 ]

 
0條 [查看全部]  相關評論

 
網站首頁 | 關于我們 | 聯系方式 | 使用協議 | 版權隱私 | 網站地圖 | 排名推廣 | 廣告服務 | 積分換禮 | 網站留言 | RSS訂閱 | 吉ICP備11001726號-6
企業800網 · 提供技術支持