Skip to content

Commit

Permalink
Merge pull request #98 from savannabits/4.x-dev
Browse files Browse the repository at this point in the history
Bug Fix: Wrong Directory Separators causing errors when registering Module Plugins
  • Loading branch information
coolsam726 authored Apr 20, 2024
2 parents 71ad0fb + 9798b19 commit d2dbd6b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions src/Commands/ModuleMakeFilamentPageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function handle(): int
->trim('/')
->trim('\\')
->trim(' ')
->replace('/', '\\');
->replace(DIRECTORY_SEPARATOR, '\\');
$pageClass = (string) str($page)->afterLast('\\');
$pageNamespace = str($page)->contains('\\') ?
(string) str($page)->beforeLast('\\') :
Expand Down Expand Up @@ -86,7 +86,7 @@ public function handle(): int
->trim('/')
->trim('\\')
->trim(' ')
->replace('/', '\\');
->replace(DIRECTORY_SEPARATOR, '\\');

if (! str($resource)->endsWith('Resource')) {
$resource .= 'Resource';
Expand Down Expand Up @@ -229,17 +229,17 @@ public function handle(): int
->implode('.'))->prepend($module->getLowerName() . '::');

$path = (string) str($page)
->prepend('/')
->prepend(DIRECTORY_SEPARATOR)
->prepend(empty($resource) ? $path : $resourcePath . "\\{$resource}\\Pages\\")
->replace('\\', '/')
->replace('//', '/')
->replace('\\', DIRECTORY_SEPARATOR)
->replace('//', DIRECTORY_SEPARATOR)
->append('.php');

$viewPath = $module->resourcesPath(
(string) str($view)
->replace($module->getLowerName() . '::', '')
->replace('.', '/')
->prepend('views/')
->replace('.', DIRECTORY_SEPARATOR)
->prepend('views' . DIRECTORY_SEPARATOR)
->append('.blade.php'),
);

Expand Down
4 changes: 2 additions & 2 deletions src/Modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function getModule(string $name): \Nwidart\Modules\Module
public function convertPathToNamespace(string $fullPath): string
{
$base = str(trim(config('modules.paths.modules', base_path('Modules')), '/\\'));
$relative = str($fullPath)->afterLast($base)->ltrim('/\\app');
$relative = str($fullPath)->afterLast($base)->replaceFirst(DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR);

return str($relative)
->ltrim('/\\')
Expand Down Expand Up @@ -49,6 +49,6 @@ public function execCommand(string $command, ?Command $artisan = null): void
public function packagePath(string $path = ''): string
{
//return the base path of this package
return dirname(__DIR__ . '../') . ($path ? DIRECTORY_SEPARATOR . trim($path, DIRECTORY_SEPARATOR) : '');
return dirname(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR) . ($path ? DIRECTORY_SEPARATOR . trim($path, DIRECTORY_SEPARATOR) : '');
}
}
2 changes: 1 addition & 1 deletion src/ModulesPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected function getModulePlugins(): array
}
// get a glob of all Filament plugins
$basePath = str(config('modules.paths.modules', 'Modules'));
$pattern = $basePath . '/*/app/Filament/*Plugin.php';
$pattern = $basePath . DIRECTORY_SEPARATOR . '*' . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'Filament' . DIRECTORY_SEPARATOR . '*Plugin.php';
$pluginPaths = glob($pattern);

return collect($pluginPaths)->map(fn ($path) => FilamentModules::convertPathToNamespace($path))->toArray();
Expand Down

0 comments on commit d2dbd6b

Please sign in to comment.