$kernel?=?$app->make(Illuminate\Contracts\Http\Kernel::class);
Instantiation Kernel
When the application is instantiated, many basic operations have been initialized. Therefore, the following construction method will directly use the dependency injection of the service container to resolve the dependencies between classes.
//?\Illuminate\Contracts\Http\Kernel?類構造器依賴?\Illuminate\Contracts\Foundation\Application?和?\Illuminate\Routing\Router,將會通過服務容器來處理依賴關系 public?function?__construct(Application?$app,?Router?$router) { ????$this->app?=?$app; ????//?主要委托?$router?來處理 ????$this->router?=?$router; ????//?以下均為中間件的設置 ????$router->middlewarePriority?=?$this->middlewarePriority; ????foreach?($this->middlewareGroups?as?$key?=>?$middleware)?{ ????????$router->middlewareGroup($key,?$middleware); ????} ????foreach?($this->routeMiddleware?as?$key?=>?$middleware)?{ ????????$router->aliasMiddleware($key,?$middleware); ????} } \Illuminate\Contracts\Foundation\Application?的處理: make?時通過別名方式直接調用?$this->instances['app'] \Illuminate\Routing\Router?的處理: make?時通過別名方式直接調用?$this->bindings['router']?數(shù)組里面?concrete?對應的匿名函數(shù) Router?依賴?\Illuminate\Contracts\Events\Dispatcher?和?\Illuminate\Container\Container public?function?__construct(Dispatcher?$events,?Container?$container?=?null) { ????$this->events?=?$events; ????$this->routes?=?new?RouteCollection; ????$this->container?=?$container??:?new?Container; } \Illuminate\Contracts\Events\Dispatcher?的處理: make?時通過別名方式直接調用?$this->bindings['events']?數(shù)組里面?concrete?對應的匿名函數(shù) Dispatcher?依賴?\Illuminate\Contracts\Container\Container public?function?__construct(ContainerContract?$container?=?null) { ????$this->container?=?$container??:?new?Container; } \Illuminate\Container\Container?的處理: make?時直接調用?$this->instances['Illuminate\Container\Container']?=?Object(app) \Illuminate\Contracts\Container\Container?的處理: make?時調用別名直接調用?$this->instances['app']?=?Object(app) 上面兩個一樣,沒有區(qū)別
Note: The dependencies listed above are all directly entrusted to the service container for automatic processing. There is no need to be afraid
of $this-> For the processing of bindings['router'] and $this->bindings['events'] binding events, the anonymous function corresponding to the array key concrete will be directly called during make.
Code snippets used during make
############################################## 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); \Illuminate\Routing\Router public?function?__construct(Dispatcher?$events,?Container?$container?=?null) { ????$this->events?=?$events; ????$this->routes?=?new?RouteCollection; ????$this->container?=?$container??:?new?Container; }
Returns a Router object and resets $this->instances['router'] = $router object for direct call next time .
$this->bindings['events']?=?[ ????'concrete'?=>?function?($app)?{ ????????????return?(new?Dispatcher($app))->setQueueResolver(function?()?use?($app)?{ ????????????????return?$app->make(QueueFactoryContract::class); ????????????}); ????????????} ????'shared'?=>?'true', ]; $dispatcher?=?(new?\Illuminate\Events\Dispatcher($app))->setQueueResolver(function?()?use?($app)?{ ????????????????return?$app->make(QueueFactoryContract::class); ????????????}); Illuminate\Events\Dispatcher: public?function?__construct(ContainerContract?$container?=?null) { ????$this->container?=?$container??:?new?Container; } public?function?setQueueResolver(callable?$resolver) { ????$this->queueResolver?=?$resolver; ????return?$this; }
Returns a Dispatcher object and resets $this->instances['events'] = $dispatcher object for direct call next time.
Note:
The kernel object is an object that combines application and routing, and the routing injects the IlluminateEventsDispatcher object, which is the core object.