潇湘沐
原理很简单1.首先,你注意一下/config/app.php里面/*|--------------------------------------------------------------------------|ClassAliases|--------------------------------------------------------------------------||Thisarrayofclassaliaseswillberegisteredwhenthisapplication|isstarted.However,feelfreetoregisterasmanyasyouwishas|thealiasesare"lazy"loadedsotheydon'thinderperformance.|*/'aliases'=>['Route'=>Illuminate\Support\Facades\Route::class,];2.因为有Facades,所以我们直接去看Illuminate\Support\Facades\Route::class这个类返回的内容*@methodstatic\Illuminate\Routing\Routeget(string$uri,\Closure|array|string$action)/***Gettheregisterednameofthecomponent.**@returnstring*/protectedstaticfunctiongetFacadeAccessor(){return'router';}3.那就简单了,直接去找注册为router的组件发现是在Illuminate/Routing/RoutingServiceProvider.php/***Registertherouterinstance.**@returnvoid*/protectedfunctionregisterRouter(){$this->app->singleton('router',function($app){returnnewRouter($app['events'],$app);});}4.newRouter()看到了没,很显然就会返回Illuminate/Routing/Router.php实例;是不是发现了publicfunctionget($uri,$action=null){return$this->addRoute(['GET','HEAD'],$uri,$action);}(づ ̄3 ̄)づ╭❤~请宣我!!么么问答时间我们可以确认了'router'是在Illuminate/Routing/RoutingServiceProvider.php里面的但是为什么没有配置在/config/app.php的providers里面呢答案在这里Illuminate/Foundation/Application.php注意baseserviceproviders和configuredproviders这个答案排版放不下了,放到了文章里面问答的其它问题