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方法:
    1. Illuminate\Foundation\Bootstrap\DetectEnvironment 环境配置($app[‘env’])
    2. Illuminate\Foundation\Bootstrap\LoadConfiguration  基本配置($app[‘config’])
    3. Illuminate\Foundation\Bootstrap\ConfigureLogging   日志文件($app[‘log’])
    4. Illuminate\Foundation\Bootstrap\HandleExceptions   错误&异常处理
    5. Illuminate\Foundation\Bootstrap\RegisterFacades    清除已解析的Facade并重新启动,注册config文件中alias定义的所有Facade类到容器
    6. Illuminate\Foundation\Bootstrap\RegisterProviders  注册config中providers定义的所有Providers类到容器
    7. 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 启动过程分析 [转]的更多相关文章

  1. Laravel 5.x 启动过程分析

     Posted on 2015年9月11日 by  学院君 1.初始化Application 1.1 注册基本绑定 app -> Application实例(Illuminate\Foundat ...

  2. ASP.Net Core MVC6 RC2 启动过程分析[偏源码分析]

    入口程序 如果做过Web之外开发的人,应该记得这个是标准的Console或者Winform的入口.为什么会这样呢? .NET Web Development and Tools Blog ASP.NE ...

  3. 开机SystemServer到ActivityManagerService启动过程分析

    开机SystemServer到ActivityManagerService启动过程 一 从Systemserver到AMS zygote-> systemserver:java入层口: /** ...

  4. Neutron分析(2)——neutron-server启动过程分析

    neutron-server启动过程分析 1. /etc/init.d/neutron-server DAEMON=/usr/bin/neutron-server DAEMON_ARGS=" ...

  5. linux视频学习7(ssh, linux启动过程分析,加解压缩,java网络编程)

    回顾数据库mysql的备份和恢复: show databases; user spdb1; show tables; 在mysql/bin目录下 执行备份: ./mysqldump -u root - ...

  6. Activity启动过程分析

    Android的四大组件中除了BroadCastReceiver以外,其他三种组件都必须在AndroidManifest中注册,对于BroadCastReceiver来说,它既可以在AndroidMa ...

  7. Spark Streaming应用启动过程分析

    本文为SparkStreaming源码剖析的第三篇,主要分析SparkStreaming启动过程. 在调用StreamingContext.start方法后,进入JobScheduler.start方 ...

  8. ActivityManagerService启动过程分析

    之前讲Android的View的绘制原理和流程的时候,讲到过在Android调用setContentView之后,Android调用了一个prepreTravle的方法,这里面就提到了Activity ...

  9. Disconf源码分析之启动过程分析下(2)

    接上文,下面是第二次扫描的XML配置. <bean id="disconfMgrBean2" class="com.baidu.disconf.client.Dis ...

随机推荐

  1. ubuntu和win7 64双系统 安装

    我是thinkpad机器 主要参考到是http://www.weste.net/2012/4-29/82173.html这个地址到教程,表示感谢 这边说下安装好以后到环境设置 首先要 sudo apt ...

  2. Generate transparent shape on image

    Here is an example code to generate transparent shape on image. Need to pay attention can not use cv ...

  3. EUI RadioButton,RadioButtonGroup实现多选项按钮

    一 自动创建的RadioButtonGroup RadioButtonGroup不能在exml里拖动创建,也不能在exml源码里创建.因为wing没提供... 一个exml上摆放的多个RadioBut ...

  4. dubbo-monitor图标功能不显示

    原因有3: 1.需要创建目录 2.需要在consumer的配置文件中增加如下配置,使用zk为注册中心 <!-- 监控中心,需要配置以后dubbo-monitor才能生效 -->    &l ...

  5. vim的树形菜单NERDTREE的设置

    网上比较好的一篇文章:http://coolshell.cn/articles/1679.html http://coolshell.cn/articles/11312.html 1.Vim安装NER ...

  6. hive中分析函数window子句

    hive中有些分析函数功能确实很强大,在和sum,max等聚合函数结合起来能实现不少功能. 直接上代码演示吧 原始数据 channel1 2016-11-10 1 channel1 2016-11-1 ...

  7. Google V8编程详解(三)Handle & HandleScope

    上一章简单的演示了一个Helloworld Demo.里面涉及到了V8的一些基本类型和概念,本章将围绕这个Demo对V8的基本类型和相关概念进行讲解. 这里还是先把Demo贴出来便于后面分析: #in ...

  8. WAP端 touch事件触发顺序记录

    IOS7.0 safari 滚动滚动条的时候, 最后手指放开 (scroll 总是在 touchend后面,所以要用 setTimeout) touchstart touchmove(多个) touc ...

  9. apche 虚拟主机设置

    <要求>:两个不同的域名 www.got7.com 和www.wgayi.com 指向同一个IP地址当在浏览器中输入不同的域名时.对应不同的网站根目录 备注:域名got7,wgayi,纯属 ...

  10. MongoDB-JAVA-Driver 3.2版本常用代码全整理(4) - 地理空间索引

    MongoDB的3.x版本Java驱动相对2.x做了全新的设计,类库和使用方法上有很大区别.例如用Document替换BasicDBObject.通过Builders类构建Bson替代直接输入$命令等 ...