Skip to content

Commit

Permalink
Merge pull request #96 from savannabits/4.x-dev
Browse files Browse the repository at this point in the history
Attempt 3: To Fix convertPathToNamespace for windows platform
  • Loading branch information
coolsam726 authored Apr 19, 2024
2 parents 8028f6c + ff4082c commit a9bab4a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/Modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ public function getModule(string $name): \Nwidart\Modules\Module

public function convertPathToNamespace(string $fullPath): string
{
$base = str(trim(config('modules.paths.modules', base_path('Modules')), DIRECTORY_SEPARATOR . '/'));
$relative = str($fullPath)->afterLast($base)->replaceFirst(DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR);
$base = str(trim(config('modules.paths.modules', base_path('Modules')), '/\\'));
$relative = str($fullPath)->afterLast($base)->ltrim('/\\app');

return str($relative)
->ltrim(DIRECTORY_SEPARATOR . '/')
->prepend(DIRECTORY_SEPARATOR . '/')
->ltrim('/\\')
->prepend(DIRECTORY_SEPARATOR)
->prepend(config('modules.namespace', 'Modules'))
->replace(DIRECTORY_SEPARATOR, '\\')
->replace('\\\\', '\\')
Expand Down
4 changes: 1 addition & 3 deletions tests/Unit/ModulesSingletonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
use Coolsam\Modules\Facades\FilamentModules;

test('can convert path to namespace correctly', function () {
$path = DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'Providers' . DIRECTORY_SEPARATOR . 'AppServiceProvider.php';

$path = config('modules.paths.modules') . '/app/Providers/TestServiceProvider.php';
$path = config('modules.paths.modules') . '\app\Providers\TestServiceProvider.php';
$namespace = FilamentModules::convertPathToNamespace($path);
expect($namespace)->toBe($expected = 'Modules\\Providers\\TestServiceProvider', "Expected $expected Instead got " . $namespace);
});

0 comments on commit a9bab4a

Please sign in to comment.