Skip to content

Commit

Permalink
add ability to loading cached Routes for application using callback
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedabdel3al committed May 4, 2024
1 parent 8c684a2 commit 9aebca8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Illuminate/Foundation/Configuration/ApplicationBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
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 $loadCachedRoutesUsing;

/**
* 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 $loadCachedRoutesCallback
* @return void
*/
public static function loadCachedRoutesUsing(?Closure $loadCachedRoutesCallback)
{
self::$loadCachedRoutesUsing = $loadCachedRoutesCallback;
}

/**
* Set the root controller namespace for the application.
*
Expand Down Expand Up @@ -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();
});
Expand Down

0 comments on commit 9aebca8

Please sign in to comment.