亚洲中字慕日产2020,大陆极品少妇内射AAAAAA,无码av大香线蕉伊人久久,久久精品国产亚洲av麻豆网站

資訊專欄INFORMATION COLUMN

Laravel kernel實(shí)例化

meteor199 / 2111人閱讀

摘要:實(shí)例化實(shí)例化在應(yīng)用進(jìn)行實(shí)例化時(shí),已經(jīng)初始化了很多的基礎(chǔ)操作,所以下面的構(gòu)造方法將會(huì)直接使用服務(wù)容器的依賴注入來解決類之間的依賴關(guān)系。返回一個(gè)對象,同時(shí)會(huì)重置對象,供下次直接調(diào)用。

Laravel Kernel實(shí)例化
$kernel = $app->make(IlluminateContractsHttpKernel::class);
實(shí)例化 Kernel

在應(yīng)用進(jìn)行實(shí)例化時(shí),已經(jīng)初始化了很多的基礎(chǔ)操作,所以下面的構(gòu)造方法將會(huì)直接使用服務(wù)容器的依賴注入來解決類之間的依賴關(guān)系。

// IlluminateContractsHttpKernel 類構(gòu)造器依賴 IlluminateContractsFoundationApplication 和 IlluminateRoutingRouter,將會(huì)通過服務(wù)容器來處理依賴關(guān)系
public function __construct(Application $app, Router $router)
{
    $this->app = $app;

    // 主要委托 $router 來處理
    $this->router = $router;
    // 以下均為中間件的設(shè)置
    $router->middlewarePriority = $this->middlewarePriority;

    foreach ($this->middlewareGroups as $key => $middleware) {
        $router->middlewareGroup($key, $middleware);
    }

    foreach ($this->routeMiddleware as $key => $middleware) {
        $router->aliasMiddleware($key, $middleware);
    }
}

IlluminateContractsFoundationApplication 的處理:
make 時(shí)通過別名方式直接調(diào)用 $this->instances["app"]

IlluminateRoutingRouter 的處理:
make 時(shí)通過別名方式直接調(diào)用 $this->bindings["router"] 數(shù)組里面 concrete 對應(yīng)的匿名函數(shù)
Router 依賴 IlluminateContractsEventsDispatcher 和 IlluminateContainerContainer
public function __construct(Dispatcher $events, Container $container = null)
{
    $this->events = $events;
    $this->routes = new RouteCollection;
    $this->container = $container ?: new Container;
}

IlluminateContractsEventsDispatcher 的處理:
make 時(shí)通過別名方式直接調(diào)用 $this->bindings["events"] 數(shù)組里面 concrete 對應(yīng)的匿名函數(shù)
Dispatcher 依賴 IlluminateContractsContainerContainer
public function __construct(ContainerContract $container = null)
{
    $this->container = $container ?: new Container;
}

IlluminateContainerContainer 的處理:
make 時(shí)直接調(diào)用 $this->instances["IlluminateContainerContainer"] = Object(app)
IlluminateContractsContainerContainer 的處理:
make 時(shí)調(diào)用別名直接調(diào)用 $this->instances["app"] = Object(app)
上面兩個(gè)一樣,沒有區(qū)別

注意:以上所列出的依賴關(guān)系,都直接委托給服務(wù)容器進(jìn)行自動(dòng)處理了,不需要怕怕

對 $this->bindings["router"] 和 $this->bindings["events"] 綁定事件的處理,make 時(shí)將會(huì)直接調(diào)用數(shù)組鍵 concrete 對應(yīng)的匿名函數(shù)。

make 時(shí)使用到的代碼片段

##############################################
if ($concrete instanceof Closure) {            
    return $concrete($this, end($this->with)); 
}
###############################################

$this->bindings["router"] = [
        "concrete" => function ($app) {
                            return new Router($app["events"], $app);
                        },
        "shared" => "true",
    ];
$router = new Router($app["events"], $app);

IlluminateRoutingRouter
public function __construct(Dispatcher $events, Container $container = null)
{
    $this->events = $events;
    $this->routes = new RouteCollection;
    $this->container = $container ?: new Container;
}

返回一個(gè) Router 對象,同時(shí)會(huì)重置 $this->instances["router"] = $router 對象,供下次直接調(diào)用。

$this->bindings["events"] = [
    "concrete" => function ($app) {
            return (new Dispatcher($app))->setQueueResolver(function () use ($app) {
                return $app->make(QueueFactoryContract::class);
            });
            }
    "shared" => "true",
];

$dispatcher = (new IlluminateEventsDispatcher($app))->setQueueResolver(function () use ($app) {
                return $app->make(QueueFactoryContract::class);
            });

IlluminateEventsDispatcher:
public function __construct(ContainerContract $container = null)
{
    $this->container = $container ?: new Container;
}
public function setQueueResolver(callable $resolver)
{
    $this->queueResolver = $resolver;

    return $this;
}

返回一個(gè) Dispatcher 對象,同時(shí)會(huì)重置 $this->instances["events"] = $dispatcher 對象,供下次直接調(diào)用。

注意:
kernel對象是融合了應(yīng)用和路由的對象,路由又注入了IlluminateEventsDispatcher對象,此為核心對象。

文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請注明本文地址:http://www.ezyhdfw.cn/yun/22611.html

相關(guān)文章

  • Laravel 動(dòng)態(tài)添加 Artisan 命令的最佳實(shí)踐

    摘要:初步嘗試既然最常見的注冊命令的方式是修改類中的,那么一般正常人都會(huì)從這邊開始下手。又要自己取出實(shí)例,又要自己調(diào)用方法,調(diào)用方法之前還有自己先把實(shí)例化這么繁瑣,肯定不是運(yùn)行時(shí)添加命令的最佳實(shí)踐,所以我決定繼續(xù)尋找更優(yōu)解。 本文首發(fā)于我的博客,原文鏈接:https://blessing.studio/best-... 雖然 Laravel 官方文檔提供的添加 Artisan Command...

    ninefive 評論0 收藏0
  • Laravel 請求周期

    摘要:請求周期加載自動(dòng)加載器獲取應(yīng)用對象實(shí)例化應(yīng)用解析此對象貫穿全文主要過程設(shè)置基礎(chǔ)路徑基礎(chǔ)綁定注冊全局基礎(chǔ)服務(wù)核心容器別名設(shè)置注冊三個(gè)單例獲取對象實(shí)例化此對象為應(yīng)用的樞紐,將會(huì)協(xié)調(diào)各部分之間的工作,完成請求主要過程注入應(yīng)用對象注入事件對象注入 Laravel 請求周期 加載 composer 自動(dòng)加載器 require __DIR__./../bootstrap/autoload.php;...

    Cristalven 評論0 收藏0
  • Laravel源碼解析之反射的使用

    摘要:本章講解反射類的使用及對反射的使用。各位很清楚,方法用于解析類,所有方法的實(shí)現(xiàn)一定是在引用的文件內(nèi)。致謝感謝你看到這里,本篇文章源碼解析靠個(gè)人理解。 showImg(https://segmentfault.com/img/bVbhjvY?w=600&h=296); 前言 PHP的反射類與實(shí)例化對象作用相反,實(shí)例化是調(diào)用封裝類中的方法、成員,而反射類則是拆封類中的所有方法、成員變量,并...

    pinecone 評論0 收藏0
  • Laravel學(xué)習(xí):請求到響應(yīng)的生命周期

    摘要:請求處理階段請求處理階段首先是準(zhǔn)備請求處理的環(huán)境,包括環(huán)境加載服務(wù)提供者注冊等環(huán)節(jié),然后將請求實(shí)例通過中間件處理及通過路由和控制器的分發(fā)控制,使得不同的請求通過相應(yīng)的處理程序進(jìn)行處理并生成響應(yīng)的過程。 Laravel請求到響應(yīng)的整個(gè)執(zhí)行過程,主要可以歸納為四個(gè)階段,即程序啟動(dòng)準(zhǔn)備階段、請求實(shí)例化階段、請求處理階段、響應(yīng)發(fā)送和程序終止階段。 程序啟動(dòng)準(zhǔn)備階段 服務(wù)容器實(shí)例化 服務(wù)容器的實(shí)...

    OBKoro1 評論0 收藏0
  • Laravel 啟動(dòng)流程

    摘要:年月日階段劃分請求到響應(yīng)的整個(gè)執(zhí)行階段歸納為個(gè)程序啟動(dòng)準(zhǔn)備階段文件自動(dòng)加載服務(wù)容器實(shí)例化基礎(chǔ)服務(wù)提供者的注冊核心類的實(shí)例化請求實(shí)例化階段實(shí)例化實(shí)例請求處理階段準(zhǔn)備請求處理的環(huán)境將請求實(shí)例通過中間件處理及通過路由和控制器的分發(fā)控制響應(yīng)發(fā)送和 Last-Modified: 2019年5月10日16:19:07 階段劃分 Laravel 5.5請求到響應(yīng)的整個(gè)執(zhí)行階段歸納為 4 個(gè): ...

    VPointer 評論0 收藏0

發(fā)表評論

0條評論

最新活動(dòng)
閱讀需要支付1元查看
<