Skip to content

Commit 279c444

Browse files
[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 <taylor@laravel.com>
1 parent dbcad29 commit 279c444

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/Illuminate/Foundation/Support/Providers/RouteServiceProvider.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ class RouteServiceProvider extends ServiceProvider
3636
*/
3737
protected static $alwaysLoadRoutesUsing;
3838

39+
/**
40+
* The callback that should be used to load the application's cached routes.
41+
*
42+
* @var \Closure|null
43+
*/
44+
protected static $alwaysLoadCachedRoutesUsing;
45+
3946
/**
4047
* Register any application services.
4148
*
@@ -93,6 +100,17 @@ public static function loadRoutesUsing(?Closure $routesCallback)
93100
self::$alwaysLoadRoutesUsing = $routesCallback;
94101
}
95102

103+
/**
104+
* Register the callback that will be used to load the application's cached routes.
105+
*
106+
* @param \Closure|null $routesCallback
107+
* @return void
108+
*/
109+
public static function loadCachedRoutesUsing(?Closure $routesCallback)
110+
{
111+
self::$alwaysLoadCachedRoutesUsing = $routesCallback;
112+
}
113+
96114
/**
97115
* Set the root controller namespace for the application.
98116
*
@@ -122,6 +140,12 @@ protected function routesAreCached()
122140
*/
123141
protected function loadCachedRoutes()
124142
{
143+
if (! is_null(self::$alwaysLoadCachedRoutesUsing)) {
144+
$this->app->call(self::$alwaysLoadCachedRoutesUsing);
145+
146+
return;
147+
}
148+
125149
$this->app->booted(function () {
126150
require $this->app->getCachedRoutesPath();
127151
});

0 commit comments

Comments
 (0)