Lumen 中 'web.php' 中定义的 '$router' 变量在哪里?

Where is the '$router' variable defined in 'web.php' in Lumen?

找不到 $router 变量在 Lumen web.php 中定义的位置。 web.php的内容就是这样,不清楚$router变量是怎么定义的:

<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It is a breeze. Simply tell Lumen the URIs it should respond to
| and give it the Closure to call when that URI is requested.
|
*/
$router->get('/', function () use ($router) {
    return $router->app->version();
});

如您所见,$router 变量没有预定义。它是从另一个文件加载到这里的吗?

这很神奇 :) 如果您打开 bootstrap/app.php,它会引导整个应用程序并加载路由,您将看到以下代码:

$app->router->group([
    'namespace' => 'App\Http\Controllers',
], function ($router) {
    require __DIR__.'/../routes/web.php';
});

因此 $routerweb.php 文件中作为全局文件可用 属性。