Skip to content

Commit

Permalink
Early Registration of the Main providers for each module.
Browse files Browse the repository at this point in the history
- This avoids Panels from being booted before the Module providers are registered.
  • Loading branch information
coolsam726 committed Apr 16, 2024
1 parent 76a3ecb commit 45a1fe2
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/ModulesServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Coolsam\Modules;

use Coolsam\Modules\Facades\FilamentModules;
use Coolsam\Modules\Testing\TestsModules;
use Filament\Support\Assets\Asset;
use Filament\Support\Facades\FilamentAsset;
Expand Down Expand Up @@ -60,8 +61,23 @@ public function packageRegistered(): void
$this->registerModuleMacros();
}

public function attemptToRegisterModuleProviders(): void
{
// It is necessary to register them here to avoid late registration (after Panels have already been booted)
$providers = glob(config('modules.paths.modules').'/*/*/Providers/*ServiceProvider.php');
foreach ($providers as $provider) {
$namespace = FilamentModules::convertPathToNamespace($provider);
$module = str($namespace)->before('\Providers\\')->afterLast('\\')->toString();
$className = str($namespace)->afterLast('\\')->toString();
if (str($className)->startsWith($module)){
// register the module service provider
$this->app->register($namespace);
}
}
}
public function packageBooted(): void
{
$this->attemptToRegisterModuleProviders();
// Asset Registration
FilamentAsset::register(
$this->getAssets(),
Expand Down

0 comments on commit 45a1fe2

Please sign in to comment.