laravel index
index.php
一、检查应用程序是否在维护中
if (file_exists(__DIR__.'/../storage/framework/maintenance.php')) {
require __DIR__.'/../storage/framework/maintenance.php';
}
二、运行应用程序
1、调用引导文件以获取应用实例(容器)
$app = require_once __DIR__.'/../bootstrap/app.php';
app.php
-
实例化Illuminate\Foundation\Applicaate类,获取一个应用实例(容器)
$app = new Illuminate\Foundation\Application( $_ENV['APP_BASE_PATH'] ?? dirname(__DIR__) ); -
单例模式绑定三个重要的接口以及对应的实现类
$app->singleton( Illuminate\Contracts\Http\Kernel::class, App\Http\Kernel::class ); $app->singleton( Illuminate\Contracts\Console\Kernel::class, App\Console\Kernel::class ); $app->singleton( Illuminate\Contracts\Debug\ExceptionHandler::class, App\Exceptions\Handler::class ); -
返回应用实例(容器)
return $app;
三、向容器中注入Http\Kernel的http核心类,目的是把中间件都加入到容器中
$kernel = $app->make(Kernel::class);
四、处理http请求
$response = tap($kernel->handle(
$request = Request::capture()
))->send();
五、清除本次请求的中间件
$kernel->terminate($request, $response);

浙公网安备 33010602011771号