From 279c444b70a28c3a2187899ba420364cac9b702a Mon Sep 17 00:00:00 2001 From: Ahmed Abdelaal <35740977+ahmedabdel3al@users.noreply.github.com> Date: Mon, 6 May 2024 20:26:21 +0300 Subject: [PATCH] [11.x] Add ability to override the default loading cached Routes for application (#51292) * add ability to loading cached Routes for application using callback * remove method --------- Co-authored-by: Taylor Otwell --- .../Providers/RouteServiceProvider.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/Illuminate/Foundation/Support/Providers/RouteServiceProvider.php b/src/Illuminate/Foundation/Support/Providers/RouteServiceProvider.php index 72ba1cc1abd2..ad881b371193 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 $alwaysLoadCachedRoutesUsing; + /** * 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 $routesCallback + * @return void + */ + public static function loadCachedRoutesUsing(?Closure $routesCallback) + { + self::$alwaysLoadCachedRoutesUsing = $routesCallback; + } + /** * Set the root controller namespace for the application. * @@ -122,6 +140,12 @@ protected function routesAreCached() */ protected function loadCachedRoutes() { + if (! is_null(self::$alwaysLoadCachedRoutesUsing)) { + $this->app->call(self::$alwaysLoadCachedRoutesUsing); + + return; + } + $this->app->booted(function () { require $this->app->getCachedRoutesPath(); });