Improve module loading
This commit is contained in:
@@ -49,6 +49,10 @@ function modules_path(string $path = ''): string
|
||||
*/
|
||||
function modules(bool $withDisabled = false): Collection
|
||||
{
|
||||
if (temp_cache()->has('modules')) {
|
||||
return temp_cache('modules');
|
||||
}
|
||||
|
||||
/** @var array<int, string> */
|
||||
$modulesDir = File::directories(modules_path());
|
||||
$modules = collect();
|
||||
@@ -74,5 +78,19 @@ function modules(bool $withDisabled = false): Collection
|
||||
}
|
||||
}
|
||||
|
||||
temp_cache()->put('modules', $modules);
|
||||
|
||||
return $modules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Temprory cache for single request
|
||||
*/
|
||||
function temp_cache(string $key = ''): mixed
|
||||
{
|
||||
$tempCache = cache()->driver('array');
|
||||
|
||||
return ($key !== '')
|
||||
? $tempCache->get($key)
|
||||
: cache()->driver('array');
|
||||
}
|
||||
|
||||
@@ -31,6 +31,11 @@ class AppServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function registerModules(): void
|
||||
{
|
||||
modules();
|
||||
$migrationDirectories = [];
|
||||
modules()->each(function ($module) use (&$migrationDirectories) {
|
||||
is_dir($module['path'].'/Database/Migrations') ? array_push($migrationDirectories, $module['path'].'/Database/Migrations') : ''; // @phpstan-ignore-line
|
||||
});
|
||||
|
||||
$this->loadMigrationsFrom($migrationDirectories);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user