Skip to content

Commit

Permalink
Bug Fix: Registering Module Service Providers was not working on wind…
Browse files Browse the repository at this point in the history
…ows.

- Changed Directory separator to be platform independent.
  • Loading branch information
coolsam726 committed Apr 19, 2024
1 parent 8c454e8 commit 85f9e57
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/ModulesServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,18 @@ public function packageRegistered(): void
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');
$providers = glob(config('modules.paths.modules') . '/*' . DIRECTORY_SEPARATOR . '*' . DIRECTORY_SEPARATOR . 'Providers' . DIRECTORY_SEPARATOR . '*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)){
if (str($className)->startsWith($module)) {
// register the module service provider
$this->app->register($namespace);
}
}
}

public function packageBooted(): void
{
$this->attemptToRegisterModuleProviders();
Expand All @@ -94,7 +95,7 @@ public function packageBooted(): void

// Handle Stubs
if (app()->runningInConsole()) {
foreach (app(Filesystem::class)->files(__DIR__.'/../stubs/') as $file) {
foreach (app(Filesystem::class)->files(__DIR__ . '/../stubs/') as $file) {
$this->publishes([
$file->getRealPath() => base_path("stubs/modules/{$file->getFilename()}"),
], 'modules-stubs');
Expand Down Expand Up @@ -187,44 +188,44 @@ protected function registerModuleMacros(): void
$relativeNamespace = str_replace('App\\', '', $relativeNamespace);
$relativeNamespace = str_replace('App', '', $relativeNamespace);
$relativeNamespace = trim($relativeNamespace, '\\');
$relativeNamespace = '\\'.$relativeNamespace;
$relativeNamespace = '\\' . $relativeNamespace;

return $this->namespace($relativeNamespace);

Check failure on line 193 in src/ModulesServiceProvider.php

View workflow job for this annotation

GitHub Actions / phpstan

Call to an undefined method Coolsam\Modules\ModulesServiceProvider::namespace().
});
Module::macro('appPath', function (string $relativePath = '') {
$appPath = $this->getExtraPath('app');

Check failure on line 196 in src/ModulesServiceProvider.php

View workflow job for this annotation

GitHub Actions / phpstan

Call to an undefined method Coolsam\Modules\ModulesServiceProvider::getExtraPath().

return $appPath.($relativePath ? DIRECTORY_SEPARATOR.$relativePath : '');
return $appPath . ($relativePath ? DIRECTORY_SEPARATOR . $relativePath : '');
});

Module::macro('databasePath', function (string $relativePath = '') {
$appPath = $this->getExtraPath('database');

Check failure on line 202 in src/ModulesServiceProvider.php

View workflow job for this annotation

GitHub Actions / phpstan

Call to an undefined method Coolsam\Modules\ModulesServiceProvider::getExtraPath().

return $appPath.($relativePath ? DIRECTORY_SEPARATOR.$relativePath : '');
return $appPath . ($relativePath ? DIRECTORY_SEPARATOR . $relativePath : '');
});

Module::macro('resourcesPath', function (string $relativePath = '') {
$appPath = $this->getExtraPath('resources');

Check failure on line 208 in src/ModulesServiceProvider.php

View workflow job for this annotation

GitHub Actions / phpstan

Call to an undefined method Coolsam\Modules\ModulesServiceProvider::getExtraPath().

return $appPath.($relativePath ? DIRECTORY_SEPARATOR.$relativePath : '');
return $appPath . ($relativePath ? DIRECTORY_SEPARATOR . $relativePath : '');
});

Module::macro('migrationsPath', function (string $relativePath = '') {
$appPath = $this->databasePath('migrations');

Check failure on line 214 in src/ModulesServiceProvider.php

View workflow job for this annotation

GitHub Actions / phpstan

Call to an undefined method Coolsam\Modules\ModulesServiceProvider::databasePath().

return $appPath.($relativePath ? DIRECTORY_SEPARATOR.$relativePath : '');
return $appPath . ($relativePath ? DIRECTORY_SEPARATOR . $relativePath : '');
});

Module::macro('seedersPath', function (string $relativePath = '') {
$appPath = $this->databasePath('seeders');

Check failure on line 220 in src/ModulesServiceProvider.php

View workflow job for this annotation

GitHub Actions / phpstan

Call to an undefined method Coolsam\Modules\ModulesServiceProvider::databasePath().

return $appPath.($relativePath ? DIRECTORY_SEPARATOR.$relativePath : '');
return $appPath . ($relativePath ? DIRECTORY_SEPARATOR . $relativePath : '');
});

Module::macro('factoriesPath', function (string $relativePath = '') {
$appPath = $this->databasePath('factories');

Check failure on line 226 in src/ModulesServiceProvider.php

View workflow job for this annotation

GitHub Actions / phpstan

Call to an undefined method Coolsam\Modules\ModulesServiceProvider::databasePath().

return $appPath.($relativePath ? DIRECTORY_SEPARATOR.$relativePath : '');
return $appPath . ($relativePath ? DIRECTORY_SEPARATOR . $relativePath : '');
});
}
}

0 comments on commit 85f9e57

Please sign in to comment.