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方法
- 通过
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 启动过程分析
Posted on 2015年9月11日 by 学院君 1.初始化Application 1.1 注册基本绑定 app -> Application实例(Illuminate\Foundat ...
- 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 ...
随机推荐
- Runtime Reconfiguration
https://coreos.com/etcd/docs/latest/runtime-configuration.html Runtime Reconfiguration 运行时重新配置 etcd ...
- Nginx 和 PHP的安装配置
1.安装PHP(注意系统默认安装了php,要安装高版本之前最好卸载旧版本,因为这个原因纠结了四个小时) ./configure \ --prefix=/usr/local/php \ --exec-p ...
- mac 查看无线wifi的密码
finder->应用程序->实用工具->钥匙串访问->右上角输入wifi名查找->显示密码(需要管理员账号)
- 企业级监控平台开发之nagios二次开发(七)
背景: A公司里有很多服务器(>3000台),每台服务器都有不同的用途,如DB Server.WEB Server.ESXI等,每个组使用其中的一批,每个组可能有多个服务器管理员.现在问题出来了 ...
- strcpy 和 strcat
strcpy 原型:char *strcpy( char *dest, char *src ) 头文件:#include <string.h> 功能:将src地址开始且含有NULL结束符 ...
- WinForm中WebBrowser的使用
最近由于工作需要,研究了下Winform的WebBrowser控件,在这里给大家分享下. 1.WebBrowser导航 WebBrowser在进行导航的时候需要用到Navigate(string ur ...
- SQL Server类型的对应关系
bit bool tinyint byte smallint short int int bigint long real float float double money decimal datet ...
- AndroidStudio导入项目一直卡在Building gradle project info最快速解决方案
AndroidStudio导入项目一直卡在Building gradle project info,实际上是因为你导入的这个项目使用的gradle与你已经拥有的gradle版本不一致,导致需要下载该项 ...
- StringBuilder类型
一.概念 String对象时不可变的,每次使用String类中的一个方法时,都要在内存中创建一个新的字符串对象,这就需要为该对象分配新的空间.在需要对字符串执行重复修改的情况下,与创建新的String ...
- 关于js中闭包的理解
1.以前很不理解js中闭包的概念及使用,下面来看一下 function foo() { var a = 123; var b = 456; return function () { return a; ...