入口文件 public/index.php

# 注册自动加载
require __DIR__.'/../bootstrap/autoload.php';
# 申明常量 LARAVEL_START 记录应用程序开始时间
define('LARAVEL_START', microtime(true));

# 注册 Composer 自动加载程序
// 在此过程中通过引入 /vendor/composer/autoload_files.php 完成了下列文件的载入
    // symfony/var-dumper/Symfony/Component/VarDumper/Resources/functions/dump.php
        // Symfony 提供的 dump 函数。
    // nikic/php-parser/lib/bootstrap.php
        // PHP-Parser 是一个用 PHP 编写的 PHP 解析器,目的是简化静态代码分析和操作
    // swiftmailer/swiftmailer/lib/swift_required.php
        // 不依赖于 PHP 自带 mail() 函数的 PHP 邮件类
    // ircmaxell/password-compat/lib/password.php
        // 用于 PHP 5.5 的简化密码散列 API 兼容库
    // psy/psysh/src/Psy/functions.php
        // 命令行调试支持
    // danielstjules/stringy/src/Create.php
        // 支持多字节字符串的 PHP 字符串处理库
    // laravel/framework/src/Illuminate/Foundation/helpers.php
        // laravel 自带基础函数库
    // laravel/framework/src/Illuminate/Support/helpers.php
        // laravel 自带拓展函数库
require __DIR__.'/../vendor/autoload.php';

# 加载预编译的类文件
$compiledPath = __DIR__.'/../vendor/compiled.php';

if (file_exists($compiledPath))
{
    require $compiledPath;
}
# 获取应用程序实例
$app = require_once __DIR__.'/../bootstrap/app.php';
# 实例化应用程序

// Illuminate/Foundation/Application.php@__construct
    // 注册基础绑定
        // 注册 Application 单例
    // 注册所有的基础服务提供者
        // 事件 Illuminate\Events\EventServiceProvider@register
            // 注册 events 单例为 Illuminate\Events\Dispatcher 实例
            // 并设置队列解析器为 Illuminate\Contracts\Queue\Queue
        // 路由 Illuminate\Routing\RoutingServiceProvider@register
            // Illuminate\Routing\Router          注册路由实例
            // Illuminate\Routing\UrlGenerator    注册 Url 生成器实例
            // Illuminate\Routing\Redirector      注册 Redirector(跳转)实例
            // Illuminate\Routing\ResponseFactory 注册 Response(响应)实例
    // 注册核心类别名
    // 设置基础路径
$app = new Illuminate\Foundation\Application(
    realpath(__DIR__.'/../') // 应用程序基础路径(根目录)
);


# 绑定重要接口

// $app->singleton(); 在容器中注册一个共享绑定(注册单例)

// http
$app->singleton(
    'Illuminate\Contracts\Http\Kernel',
    'App\Http\Kernel'
);
// 控制台
$app->singleton(
    'Illuminate\Contracts\Console\Kernel',
    'App\Console\Kernel'
);
// 异常处理
$app->singleton(
    'Illuminate\Contracts\Debug\ExceptionHandler',
    'App\Exceptions\Handler'
);

# 返回应用程序实例
// Illuminate/Foundation/Application.php
return $app;
# 运行应用程序
$kernel = $app->make('Illuminate\Contracts\Http\Kernel');

// 处理传入的 HTTP 请求,并获取响应实例
    // 通过中间件或路由发送给定的请求
        // 运行各引导类,调用其 bootstrap 方法,并触发“bootstrapping: Xxx”和“bootstrapped: Xxx”事件
        // 获取响应实例
            // 调用 router.before 路由前置过滤器,参数 $request
            // 若路由前置过滤器没有返回响应实例,则从一个路由调度请求,并取得响应实例
            // 调用 router.after 路由后置过滤器,参数 $request, $response
    // 触发 kernel.handled 事件,参数 $request, $response
$response = $kernel->handle(
    // 从服务器变量创建一个新的 Illuminate HTTP 请求实例
    $request = Illuminate\Http\Request::capture()
);

// 发送响应
$response->send();

// 在所有需要结束的中间件中调用 terminate 方法
$kernel->terminate($request, $response);