Laravel 5.x 启动过程分析
1、初始化Application
1.1 注册基本绑定
- app ->
Application实例(Illuminate\Foundation\Application) - Illuminate\Container\Container ->
Application实例(Illuminate\Foundation\Application)
1.2 注册基本服务提供者并启动
EventServieProvider —— 事件服务提供者
$this->app->singleton('events', function ($app) {
return (new Dispatcher($app))->setQueueResolver(function () use ($app) {
return $app->make('Illuminate\Contracts\Queue\Factory');
});
});
RoutingServiceProvider —— 路由服务提供者
public function register()
{
$this->registerRouter();
$this->registerUrlGenerator();
$this->registerRedirector();
$this->registerPsrRequest();
$this->registerPsrResponse();
$this->registerResponseFactory();
}
更多详情查看源码:Illuminate\Routing\RoutingServiceProvider.php
1.3 注册核心服务容器别名
更多详情查看源码:Illuminate\Foundation\Application.php第1026行registerCoreContainerAliases方法。
1.4 设置根路径(如果传入的话)
if ($basePath) {
$this->setBasePath($basePath);
}
更多详情查看源码:Illuminate\Foundation\Application.php第262行setBasePath方法。
2、注册共享的Kernel和异常处理器
- Illuminate\Contracts\Http\Kernel ->
App\Http\Kernel - Illuminate\Contracts\Console\Kernel ->
App\Console\Kernel - Illuminate\Contracts\Debug\ExceptionHandler ->
App\Exceptions\Handler
3、处理请求和响应
3.1 web请求
解析Illuminate\Contracts\Http\Kernel,实例化App\Http\Kernel
a.构造函数:设置$app/$router,初始化$router中middleware数值
b.handle处理请求 —— 经过路由发送请求:
- $request是经过Symfony封装的请求对象
- 注册request实例到容器
($app[‘request’]->Illuminate\Http\Request) - 清空之前容器中的request实例
- 调用
bootstrap方法,启动一系列启动类的bootstrap方法:- Illuminate\Foundation\Bootstrap\DetectEnvironment
环境配置($app[‘env’]) - Illuminate\Foundation\Bootstrap\LoadConfiguration 基本配置($app[‘config’])
- Illuminate\Foundation\Bootstrap\ConfigureLogging 日志文件($app[‘log’])
- Illuminate\Foundation\Bootstrap\HandleExceptions 错误&异常处理
- Illuminate\Foundation\Bootstrap\RegisterFacades 清除已解析的Facade并重新启动,注册config文件中alias定义的所有Facade类到容器
- Illuminate\Foundation\Bootstrap\RegisterProviders 注册config中providers定义的所有Providers类到容器
- Illuminate\Foundation\Bootstrap\BootProviders 调用所有已注册Providers的boot方法
- Illuminate\Foundation\Bootstrap\DetectEnvironment
- 通过
Pipeline发送请求,经过中间件,再由路由转发,最终返回响应new Pipeline($this->app))
->send($request) ->through($this->middleware) ->then($this->dispatchToRouter()
c.将响应信息发送到浏览器:
$response->send();
d.处理继承自TerminableMiddleware接口的中间件(Session)并结束应用生命周期:
$kernel->terminate($request, $response);
Laravel 5.x 启动过程分析的更多相关文章
- Laravel 5.x 启动过程分析 [转]
1.初始化Application 1.1 注册基本绑定 app -> Application实例(Illuminate\Foundation\Application) Illuminate\Co ...
- ASP.Net Core MVC6 RC2 启动过程分析[偏源码分析]
入口程序 如果做过Web之外开发的人,应该记得这个是标准的Console或者Winform的入口.为什么会这样呢? .NET Web Development and Tools Blog ASP.NE ...
- 开机SystemServer到ActivityManagerService启动过程分析
开机SystemServer到ActivityManagerService启动过程 一 从Systemserver到AMS zygote-> systemserver:java入层口: /** ...
- Neutron分析(2)——neutron-server启动过程分析
neutron-server启动过程分析 1. /etc/init.d/neutron-server DAEMON=/usr/bin/neutron-server DAEMON_ARGS=" ...
- linux视频学习7(ssh, linux启动过程分析,加解压缩,java网络编程)
回顾数据库mysql的备份和恢复: show databases; user spdb1; show tables; 在mysql/bin目录下 执行备份: ./mysqldump -u root - ...
- Activity启动过程分析
Android的四大组件中除了BroadCastReceiver以外,其他三种组件都必须在AndroidManifest中注册,对于BroadCastReceiver来说,它既可以在AndroidMa ...
- Spark Streaming应用启动过程分析
本文为SparkStreaming源码剖析的第三篇,主要分析SparkStreaming启动过程. 在调用StreamingContext.start方法后,进入JobScheduler.start方 ...
- ActivityManagerService启动过程分析
之前讲Android的View的绘制原理和流程的时候,讲到过在Android调用setContentView之后,Android调用了一个prepreTravle的方法,这里面就提到了Activity ...
- Disconf源码分析之启动过程分析下(2)
接上文,下面是第二次扫描的XML配置. <bean id="disconfMgrBean2" class="com.baidu.disconf.client.Dis ...
随机推荐
- 微信小程序教程系列
微信小程序教程系列 来源: https://blog.csdn.net/michael_ouyang/article/details/56846185 相关连接:http://blog.c ...
- 手贱!使用django,在数据库直接删除了表
莫名其妙的错误. 删除了migreation文件,并且更换了数据库. 1.直接makemigrations + migrate error: no change ?? WTF 2.makemi ...
- OpenACC 绘制曼德勃罗集
▶ 书上第四章,用一系列步骤优化曼德勃罗集的计算过程. ● 代码 // constants.h ; ; ; ; const double xmin=-1.7; ; const double ymin= ...
- shell随笔
一, case的详细用法: 参考文章(http://blog.csdn.net/dreamtdp/article/details/8048720) 语句实例:由用户从键盘输入一个字符,并判断该字符 ...
- leetcode937
public class Solution { public string[] ReorderLogFiles(string[] logs) { var list1 = new List<str ...
- Simple2D-14(音乐播放器)简介
接下来文章中,会介绍一个简单的程序——音乐播放器.通过编写一个音乐播放器在 Simple2D 中加入两个库:音频库 bass 和界面库 ImGui. 下面是音乐播放器的预览图: 播放器的功能比较简单, ...
- springboot测试时 SpringApplicationConfiguration注解不能用
测试时,@SpringApplicationConfiguration(classes = Application.class) 报错,注解不能导入. 在学习spring boot时,按照文档学习时测 ...
- Java 静态代理和动态代理例子
代理Proxy: Proxy代理模式是一种结构型设计模式,主要解决的问题是:在直接访问对象时带来的问题 代理是一种常用的设计模式,其目的就是为其他对象提供一个代理以控制对某个对象的访问.代理类负责为委 ...
- 分享 - 27 个机器学习、数学、Python 速查表
转载自:伯乐在线 - iPytLab,原文链接,侵删 机器学习涉及到的方面非常多.当我开始准备复习这些内容的时候,我找到了许多不同的”速查表”, 这些速查表针对某一主题都罗列出了所有我需要知道的知 ...
- Becoming inspired - ASC - 2017 MARCH 24
Becoming inspired - The 11 questions to ask yourself when you feel uninspired @ Advanced Studio Clas ...