diff --git a/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php b/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php index 642830bbe743..c1c720fb06c4 100644 --- a/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php +++ b/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php @@ -218,6 +218,19 @@ class_exists(Folio::class)) { }; } + /** + * Register loading cached routes for the application. + * + * @param \Closure $using + * @return $this + */ + public function loadCachedRoutesUsing(Closure $using) + { + AppRouteServiceProvider::loadCachedRoutesUsing($using); + + return $this; + } + /** * Register the global middleware, middleware groups, and middleware aliases for the application. * diff --git a/src/Illuminate/Foundation/Support/Providers/RouteServiceProvider.php b/src/Illuminate/Foundation/Support/Providers/RouteServiceProvider.php index 72ba1cc1abd2..19dafdc3d4d4 100644 --- a/src/Illuminate/Foundation/Support/Providers/RouteServiceProvider.php +++ b/src/Illuminate/Foundation/Support/Providers/RouteServiceProvider.php @@ -36,6 +36,13 @@ class RouteServiceProvider extends ServiceProvider */ protected static $alwaysLoadRoutesUsing; + /** + * The callback that should be used to load the application's cached routes. + * + * @var \Closure|null + */ + protected static $loadCachedRoutesUsing; + /** * Register any application services. * @@ -93,6 +100,17 @@ public static function loadRoutesUsing(?Closure $routesCallback) self::$alwaysLoadRoutesUsing = $routesCallback; } + /** + * Register the callback that will be used to load the application's cached routes. + * + * @param \Closure|null $loadCachedRoutesCallback + * @return void + */ + public static function loadCachedRoutesUsing(?Closure $loadCachedRoutesCallback) + { + self::$loadCachedRoutesUsing = $loadCachedRoutesCallback; + } + /** * Set the root controller namespace for the application. * @@ -122,6 +140,11 @@ protected function routesAreCached() */ protected function loadCachedRoutes() { + if (! is_null(self::$loadCachedRoutesUsing)) { + $this->app->call(self::$loadCachedRoutesUsing); + + return; + } $this->app->booted(function () { require $this->app->getCachedRoutesPath(); });