背景:梳理$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());