Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure the namespace of the policy file #313

Merged
merged 2 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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