new Illuminate\Foundation\Application


设置项目基础路径 setBasePath
注册基础容器 registerBaseBindings
注册基础服务 registerBaseServiceProviders
注册核心别名 到 aliases数组和abstractAliases数组
registerCoreContainerAliases
设置单例
static::setInstance($this)
注册this到 instances 数组
$this->instance('app', $this);
注册 Container 到 instances 数组
$this->instance(Container::class, $this);
注册 包管理类 PackageManifest 到 instances 数组
$this->instance(PackageManifest::class, new PackageManifest(
    new Filesystem, $this->basePath(), $this->getCachedPackagesPath()
));
basePath 默认根目录 /
path 默认 /app
path.base 默认basePath
path.lang 默认 /resources/lang
path.config 默认 /config
path.public 默认 /public
path.storage 默认 /storage
path.database 默认 /database
path.resources 默认 /resources
path.bootstrap 默认 /bootstrap



注册事件服务
$this->register(new EventServiceProvider($this));
注册日志服务
$this->register(new LogServiceProvider($this));
注册路由服务
$this->register(new RoutingServiceProvider($this));
注册mix到bingding数组并设置为共享
$this->singleton(Mix::class);
注册 'router'到 bingding 中 共享:是 
$this->registerRouter();


注册'url'(url生成器)到 bingding 中 共享:是
$this->registerUrlGenerator();


注册 'redirect'(重定向)到 bingding 中 共享:是
$this->registerRedirector();


注册 'ServerRequestInterface'(http请求接口)到 bingding 共享:否
$this->registerPsrRequest();


注册  'ServerRequestInterface'(http响应)到 bingding 共享:否
$this->registerPsrResponse();


注册  'ResponseInterface'(http响应工厂)到 bingding 共享:是
$this->registerResponseFactory();


注册 'ControllerDispatcherContract'(controller 调度器)到 bingding 共享:是
$this->registerControllerDispatcher();


注册完成会保存到 

serviceProviders


标记已保存

loadedProviders
注册 'events'到 bingding 中 共享:是 
$this->app->singleton('log', function () {})
注册 'log'到 bingding 中 共享:是 
$this->app->singleton('log', function () {})
注册 'App\Http\Kernel'(web内核)到 bingding 中 共享:是
注册 'App\Console\Kernel'(cmd内核)到 bingding 中 共享:是
注册 'App\Exceptions\Handler'(异常处理内核)到 bingding 中 共享:是
创建Http\Kernel内核(App\Http\Kernel)
$app->make(Illuminate\Contracts\Http\Kernel::class);
创建Request对象,并初始化(http请求参数)数据
$request = Illuminate\Http\Request::capture()
实际处理方法,返回 response 响应对象
$response = $kernel->handle($request);
响应数据给客户端
$response->send();
生命周期结束处理
$kernel->terminate($request, $response);
获取别名(Illuminate\Contracts\Http\Kernel)
$abstract = $this->getAlias($abstract);
$abstract = 'Illuminate\Contracts\Http\Kernel'
获取bindings中key是Illuminate\Contracts\Http\Kernel的匿名函数
$concrete = $this->getConcrete($abstract);

判断是否可以创建

$this->isBuildable($concrete, $abstract)


实例化具体
$object = $this->build($concrete);
缓存单例并标记已解析
$this->instances[$abstract] = $object;
$this->resolved[$abstract] = true;
创建全局的request对象(Symfony\Component\HttpFoundation\Request)
$request = SymfonyRequest::createFromGlobals(){
   return self::createRequestFromFactory($_GET, $_POST, [], $_COOKIE, $_FILES, $_SERVER);
}
创建一个Illuminate\Http\Request 对象
$request = Illuminate\Http\Request::createFromBase($request);
$this(App\Http\Kernel)
$response = $this->sendRequestThroughRouter($request);
触发事件 请求事件
$events = new Events\RequestHandled($request, $response)
$this->app['events']->dispatch($events);
导入和初始化配置
$this->bootstrap();
$this->app->bootstrapWith($this->bootstrappers());
触发 bootstrapping: \Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables 事件
载入env或者全局变量配置
\Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables
触发 bootstrapped: \Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables 事件
触发 bootstrapping: \Illuminate\Foundation\Bootstrap\LoadConfiguration 事件
载入config文件夹配置
\Illuminate\Foundation\Bootstrap\LoadConfiguration
触发 bootstrapped: \Illuminate\Foundation\Bootstrap\LoadConfiguration 事件
触发 bootstrapping: \Illuminate\Foundation\Bootstrap\HandleExceptions 事件
设置自定义异常处理,错误处理,进程终止钩子
\Illuminate\Foundation\Bootstrap\HandleExceptions
触发 bootstrapped: \Illuminate\Foundation\Bootstrap\HandleExceptions 事件
触发 bootstrapping: \Illuminate\Foundation\Bootstrap\RegisterFacades 事件
注册 Facades,AliasLoader(别名加载类)
\Illuminate\Foundation\Bootstrap\RegisterFacades
触发 bootstrapped: \Illuminate\Foundation\Bootstrap\RegisterFacades 事件
触发 bootstrapping: \Illuminate\Foundation\Bootstrap\RegisterProviders 事件
注册config中的app.providers 【非常核心的功能,第一次运行会对providers缓存】
他采用3种机制去实例化providers。1.立即;2.事件;3.延迟;
\Illuminate\Foundation\Bootstrap\RegisterProviders
触发 bootstrapped: \Illuminate\Foundation\Bootstrap\RegisterProviders 事件
触发 bootstrapping: \Illuminate\Foundation\Bootstrap\BootProviders事件
执行 bootingCallbacks 回调
调用 serviceProviders中每一个Providers的每一个boot方法(如果有)
执行 bootedCallbacks 回调
\Illuminate\Foundation\Bootstrap\BootProviders
触发 bootstrapped: \Illuminate\Foundation\Bootstrap\BootProviders事件
执行结束,回调钩子
Illuminate\Foundation\Bootstrap\HandleExceptions::handleShutdown
通过管道执行触发路由
(new Pipeline($this->app))->send($request)
->through($this->middleware)->then($this->dispatchToRouter())
执行默认中间件App\Http\Kernel
\App\Http\Middleware\CheckForMaintenanceMode::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
\App\Http\Middleware\TrustProxies::class,
路由处理请求
$this(App\Http\Kernel)
$this->router->dispatch($request)
匹配正确路由并执行
$this->runRoute($request, $this->findRoute($request));
触发路由匹配完成事件
$this->events->dispatch(new Events\RouteMatched($route, $request));
执行路由
$response = $this->runRouteWithinStack($route, $request)
通过管道,执行中间件,再执行路由,最后解析结果并返回
(new Pipeline($this->container))->send($request)
->through($middleware)->then(function ($request) use ($route) {
    return $this->prepareResponse(
        $request, $route->run()
    );
});
解析返回结果
$this->prepareResponse($request,response);
根据结果类型创建响应对象:
Illuminate\Routing\Router::toResponse($request, $response)
根据请求,构造响应header
$response->prepare($request);
获取路由中间件
Route::middleware('xxx')
获取控制器中间件
Controller::getMiddleware()
按中间件优先级排序
$this(Illuminate\Routing\Router)
$this->sortMiddleware($middleware)
最后执行中间件
执行路由
$route(Illuminate\Routing\Route)
$route->run()
是否是控制器
$this->isControllerAction()


执行匿名函数
$this(Illuminate\Routing\Route)
$this->runCallable()
执行控制器
$this(Illuminate\Routing\Route)
$this->runController()

执行过程省略...

执行过程省略...

laravel

laravel

2020-01-02 10:47:13 0 28
这里是评论

相关推荐