Laravel (5.5.33) 加载过程(二)
本次说明代码
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
/* |-------------------------------------------------------------------------- | Turn On The Lights |-------------------------------------------------------------------------- | | We need to illuminate PHP development, so let us turn on the lights. | This bootstraps the framework and gets it ready for use, then it | will load up this application so that we can run it and send | the responses back to the browser and delight our users. | */ $app = require_once __DIR__.'/../bootstrap/app.php';
主要实现的功能
1.实例化 Illuminate\Foundation\Application类
2.初始化基础路径
3.基本容器(app,Container)和对于类的绑定
4.基础服务的注册(事件服务EventServiceProvider 日志服务LogServiceProvider 路由服务RoutingServiceProvider)
5.别名的注册(vendor/laravel/framework/src/Illuminate/Foundation/Application.php文件中的 registerCoreContainerAliases 方法)
流程图
代码
<?php /* |-------------------------------------------------------------------------- | Create The Application |-------------------------------------------------------------------------- | | The first thing we will do is create a new Laravel application instance | which serves as the "glue" for all the components of Laravel, and is | the IoC container for the system binding all of the various parts. | */ /** * 对于其中的instance register singleton 方法到时候单独拎出来说明 * * 1.设置基础路径 * 2.使用instance 方法 绑定app 和Illuminate\Foundation\Application类的关系 * 3.使用instance 方法 绑定Container 和Illuminate\Foundation\Application类的关系 * 4.app变量中注册事件服务EventServiceProvider * 5.app变量中注册日志服务LogServiceProvider * 6.app变量中注册路由服务RoutingServiceProvider * 7.别名的注册(vendor/laravel/framework/src/Illuminate/Foundation/Application.php文件中的 registerCoreContainerAliases 方法) */ $app = new Illuminate\Foundation\Application( realpath(__DIR__.'/../') ); /* |-------------------------------------------------------------------------- | Bind Important Interfaces |-------------------------------------------------------------------------- | | Next, we need to bind some important interfaces into the container so | we will be able to resolve them when needed. The kernels serve the | incoming requests to this application from both the web and CLI. | */ /** * 把App\Http\Kernel::class 类下的参数 映射到lluminate\Contracts\Http\Kernel::class类中 */ $app->singleton( Illuminate\Contracts\Http\Kernel::class, App\Http\Kernel::class ); /** * 把App\Console\Kernel::class 类下的参数 映射到Illuminate\Contracts\Console\Kernel::class类中 */ $app->singleton( Illuminate\Contracts\Console\Kernel::class, App\Console\Kernel::class ); /** * 把App\Exceptions\Handler::class 类下的参数 映射到Illuminate\Contracts\Debug\ExceptionHandler::class类中 */ $app->singleton( Illuminate\Contracts\Debug\ExceptionHandler::class, App\Exceptions\Handler::class ); /* |-------------------------------------------------------------------------- | Return The Application |-------------------------------------------------------------------------- | | This script returns the application instance. The instance is given to | the calling script so we can separate the building of the instances | from the actual running of the application and sending responses. | */ return $app;
posted on 2018-02-16 21:44 Sunlight1992 阅读(138) 评论(0) 编辑 收藏 举报