Skip to content

Commit

Permalink
[11.x] Add ability to override the default loading cached Routes for …
Browse files Browse the repository at this point in the history
…application (#51292)

* add ability to loading cached Routes for application using callback

* remove method

---------

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
ahmedabdel3al and taylorotwell authored May 6, 2024
1 parent dbcad29 commit 279c444
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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();
});
Expand Down

0 comments on commit 279c444

Please sign in to comment.