Skip to content

Commit

Permalink
Merge pull request #313 from igwen6w/3.x
Browse files Browse the repository at this point in the history
Configure the namespace of the policy file
  • Loading branch information
bezhanSalleh committed Feb 14, 2024
2 parents 2a200ef + 1d0708e commit 95fa408
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions config/filament-shield.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
'generator' => [
'option' => 'policies_and_permissions',
'policy_directory' => 'Policies',
// The namespace of the generated policy file will be App\Policies
'namespace' => 'Policies',
],

'exclude' => [
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/Concerns/CanGeneratePolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ protected function generatePolicyStubVariables(array $entity): array
$path = $reflectionClass->getFileName();

$stubVariables['namespace'] = Str::of($path)->contains(['vendor', 'src'])
? 'App\Policies'
: Str::of($namespace)->replace('Models', 'Policies'); /** @phpstan-ignore-line */
? 'App\\' . Utils::getGeneratorNamespace()
: Str::of($namespace)->replace('Models', Utils::getGeneratorNamespace()); /** @phpstan-ignore-line */
$stubVariables['model_name'] = $entity['model'];
$stubVariables['model_fqcn'] = $namespace . '\\' . $entity['model'];
$stubVariables['model_variable'] = Str::of($entity['model'])->camel();
Expand Down
6 changes: 6 additions & 0 deletions src/Support/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ public static function getGeneratorOption(): string
return (string) config('filament-shield.generator.option', 'policies_and_permissions');
}


public static function getGeneratorNamespace(): string
{
return (string) config('filament-shield.generator.namespace', 'Policies');
}

public static function isGeneralExcludeEnabled(): bool
{
return (bool) config('filament-shield.exclude.enabled', true);
Expand Down

0 comments on commit 95fa408

Please sign in to comment.