Laravel5.5解析-$response-结构拆解

背景:梳理$response实现的过程

地址:index.php

$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()
);

handle()

	//class Illuminate\Foundation\Http\Kernel
	public function handle($request)
    {
    	//设定请求参数可覆盖
        $request->enableHttpMethodParameterOverride();
        //获取$response
        $response = $this->sendRequestThroughRouter($request);
        
        $this->app['events']->dispatch(
            new Events\RequestHandled($request, $response)
        );

        return $response;
    }

sendRequestThroughRouter()

	//class Illuminate\Foundation\Http\Kernel
	protected function sendRequestThroughRouter($request)
    {
    	//将$request注入到容器的instance中
        $this->app->instance('request', $request);
		//实现$bootstrappers
        $this->bootstrap();

        return (new Pipeline($this->app))
                    ->send($request)
                    ->through($this->app->shouldSkipMiddleware() ? [] : $this->middleware)
                    ->then($this->dispatchToRouter());
    }

bootstrap() -> boostrapWith()

	//class Illuminate\Foundation\Http\Kernel
	public function bootstrap()
    {
        $this->app->bootstrapWith($this->bootstrappers());
    }
    //class Application
    public function bootstrapWith(array $bootstrappers)
    {
        $this->hasBeenBootstrapped = true;

        foreach ($bootstrappers as $bootstrapper) {
            $this['events']->fire('bootstrapping: '.$bootstrapper, [$this]);
            $this->make($bootstrapper)->bootstrap($this);//创建实例后执行bootstrap方法
            $this['events']->fire('bootstrapped: '.$bootstrapper, [$this]);
        }
    }
    

通过容器依次实现$bootstrappers中的类

    protected $bootstrappers = [
        \Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables::class,
        \Illuminate\Foundation\Bootstrap\LoadConfiguration::class,
        \Illuminate\Foundation\Bootstrap\HandleExceptions::class,
        \Illuminate\Foundation\Bootstrap\RegisterFacades::class,
        \Illuminate\Foundation\Bootstrap\RegisterProviders::class,
        \Illuminate\Foundation\Bootstrap\BootProviders::class,
    ];

new Pipeline()获取$response

        return (new Pipeline($this->app))
                    ->send($request)
                    ->through($this->app->shouldSkipMiddleware() ? [] : $this->middleware)
                    ->then($this->dispatchToRouter());
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值