Skip to content

Commit

Permalink
Merge pull request #1 from zayedadel/patch-1
Browse files Browse the repository at this point in the history
fix: psr-4 name space problems
  • Loading branch information
A909M authored Jan 7, 2025
2 parents ebc39d9 + 30e2ba8 commit 7888da4
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions src/Commands/FilamentGenerateHelpersCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class FilamentGenerateHelpersCommand extends Command
public $signature = 'filament-generate-helpers:run {name?} {--model-namespace=} {--F|force}';

public $description = 'Create a new helper class. and generate the form and table columns methods on traits';

public function handle(): int
{
$model = (string) str($this->argument('name') ?? text(
Expand Down Expand Up @@ -50,22 +49,18 @@ public function handle(): int
$helperClass = "{$modelClass}Helper";

$path = app_path("Filament/Helpers/{$model}");
$helperNameSpace = "App\\Filament\\Helpers\\{$model}";
$helperNamespace = "App\\Filament\\Helpers\\{$model}";
$formFieldsTrait = "{$modelClass}FormFields";
$tableColumnsTrait = "{$modelClass}TableColumns";
$traits = $formFieldsTrait.','.$tableColumnsTrait;
$baseHelperPath =
(string) str($helper)
->prepend('/')
->prepend($path)
->replace('\\', '/')
->replace('//', '/');

$traits = $formFieldsTrait . ',' . $tableColumnsTrait;
$baseHelperPath = "{$path}/{$helperClass}";
$helperPath = "{$baseHelperPath}.php";
$helperTraitDirectory = "{$baseHelperPath}/Traits";
$helperTraitDirectory = "{$path}/Traits";
$formFieldsTraitPath = "{$helperTraitDirectory}/{$formFieldsTrait}.php";
$tableColumnsTraitPath = "{$helperTraitDirectory}/{$tableColumnsTrait}.php";
//
if (! $this->option('force') && $this->checkForCollision([

if (!$this->option('force') && $this->checkForCollision([
$helperPath,
$formFieldsTraitPath,
$tableColumnsTraitPath,
Expand All @@ -75,26 +70,36 @@ public function handle(): int

$this->copyStubToApp('Helper', $helperPath, [
'class' => $helperClass,
'namespace' => $helperNameSpace,
'namespace' => $helperNamespace,
'traits' => $traits,
'formFieldsTrait' => $formFieldsTrait,
'tableColumnsTrait' => $tableColumnsTrait,
'FieldsCall' => $this->indentString($this->getResourceFormSchema($modelNamespace.($modelSubNamespace !== '' ? "\\{$modelSubNamespace}" : '').'\\'.$modelClass, true) ?: '//'),
'ColumnsCall' => $this->indentString($this->getResourceTableColumns($modelNamespace.($modelSubNamespace !== '' ? "\\{$modelSubNamespace}" : '').'\\'.$modelClass, true) ?: '//'),
'FieldsCall' => $this->indentString($this->getResourceFormSchema(
$modelNamespace . ($modelSubNamespace !== '' ? "\\{$modelSubNamespace}" : '') . '\\' . $modelClass,
true
) ?: '//'),
'ColumnsCall' => $this->indentString($this->getResourceTableColumns(
$modelNamespace . ($modelSubNamespace !== '' ? "\\{$modelSubNamespace}" : '') . '\\' . $modelClass,
true
) ?: '//'),
]);

$this->copyStubToApp('FormFields', $formFieldsTraitPath, [
'trait' => $formFieldsTrait,
'namespace' => $helperNameSpace,
'functions' => $this->indentString($this->getResourceFormSchema($modelNamespace.($modelSubNamespace !== '' ? "\\{$modelSubNamespace}" : '').'\\'.$modelClass) ?: '//'),

'namespace' => "{$helperNamespace}",
'functions' => $this->indentString($this->getResourceFormSchema(
$modelNamespace . ($modelSubNamespace !== '' ? "\\{$modelSubNamespace}" : '') . '\\' . $modelClass
) ?: '//'),
]);

$this->copyStubToApp('TableColumns', $tableColumnsTraitPath, [
'trait' => $tableColumnsTrait,
'namespace' => $helperNameSpace,
'functions' => $this->indentString($this->getResourceTableColumns($modelNamespace.($modelSubNamespace !== '' ? "\\{$modelSubNamespace}" : '').'\\'.$modelClass) ?: '//'),
'namespace' => "{$helperNamespace}",
'functions' => $this->indentString($this->getResourceTableColumns(
$modelNamespace . ($modelSubNamespace !== '' ? "\\{$modelSubNamespace}" : '') . '\\' . $modelClass
) ?: '//'),
]);

$this->components->info("Filament Class helper [{$helperPath}] created successfully.");
$this->components->info("Trait Form helper [{$formFieldsTraitPath}] created successfully.");
$this->components->info("Trait Table helper [{$tableColumnsTraitPath}] created successfully.");
Expand Down

0 comments on commit 7888da4

Please sign in to comment.