laravel生命周期
2017-07-01 16:33:41   10  举报             
     
         
 AI智能生成
  php laravel 框架的生命周期图 从入口文件 index.php 到核心类 httpKernel 对象,再到response对象的创建,发送,整个过程,基于 laravel 5.2 部分细节待优化
    作者其他创作
 大纲/内容
  index.php    
     引入 bootstrap/autoload.php    
     引入 composer自动加载   
     create kernel( \Illuminate\Foundation\Http\Kernel )    
     call handle    
     call sendRequestThroughRouter              
    $this->bootstrap
 初始化                             
    bootstrapWith    'Illuminate\Foundation\Bootstrap\DetectEnvironment',
'Illuminate\Foundation\Bootstrap\LoadConfiguration',
'Illuminate\Foundation\Bootstrap\ConfigureLogging',
'Illuminate\Foundation\Bootstrap\HandleExceptions',
'Illuminate\Foundation\Bootstrap\RegisterFacades',
'Illuminate\Foundation\Bootstrap\RegisterProviders',
'Illuminate\Foundation\Bootstrap\BootProviders',
DetectEnvironment     \Dotenv\Dotenv::load  
    setEnvironmentVariable     加载 .env 文件配置到环境变量 $_SERVER数组 $_ENV 数组  
     调用apache_setenv  
     调用putenv    
     windows下存在BUG    
     一次put没完成 第二次put时会失败,对应页面卡的时候刷新第二次 读取不到值  
     值为UTF编码一个中文字符时设置失败  
    BootProviders
 加载所有用户自定义Provider    
     \App\Providers\RouteServiceProvider    
     map  
     指定路由文件路径  
     App::bootstrapWith    
     循环调用各Bootstrap 对象的 bootstrap 方法  
    $this->dispatchToRouter
 跳转到路由              
    $this->app->instance('request', $request);
 初始化request  
     App: \Illuminate\Foundation\Application  
    $this->router->dispatch($request);
 Route: \Illuminate\Routing\Router  
     Router::dispatchToRoute                   
    findRoute
 创建Route对象    
     注入到 $this->container  
     处理路由用户代码         
    \Illuminate\Routing\Route::run
 调用必包         
    $this->runCallable
 调用控制器         
    $this->runController
runRouteWithinStack     创建中间件         
    gatherRouteMiddlewares   调用路由处理         
    $route->run($request)
prepareResponse     添加http头         
    $response->prepare($request)
 得到response对象    
     \Illuminate\Http\Response  
     response::send  
     kernel::terminate    
     调用所有中间件的terminate方法  
    
 
 
 
 
  0 条评论
 下一页