Skip to content

Commit

Permalink
Allow json translation from project lang for widget nam
Browse files Browse the repository at this point in the history
  • Loading branch information
abdosaeedelhassan committed Sep 8, 2024
1 parent 48a2c32 commit 25a8aff
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 46 deletions.
6 changes: 3 additions & 3 deletions src/Commands/Concerns/CanGeneratePolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected function generatePolicyStubVariables(array $entity): array
{
$stubVariables = collect(Utils::getResourcePermissionPrefixes($entity['fqcn']))
->reduce(function ($gates, $permission) use ($entity) {
$gates[Str::studly($permission)] = $permission . '_' . $entity['resource'];
$gates[Str::studly($permission)] = $permission.'_'.$entity['resource'];

return $gates;
}, []);
Expand All @@ -59,10 +59,10 @@ protected function generatePolicyStubVariables(array $entity): array
$path = $reflectionClass->getFileName();

$stubVariables['namespace'] = Str::of($path)->contains(['vendor', 'src'])
? 'App\\' . Utils::getPolicyNamespace()
? 'App\\'.Utils::getPolicyNamespace()
: Str::of($namespace)->replace('Models', Utils::getPolicyNamespace()); /** @phpstan-ignore-line */
$stubVariables['model_name'] = $entity['model'];
$stubVariables['model_fqcn'] = $namespace . '\\' . $entity['model'];
$stubVariables['model_fqcn'] = $namespace.'\\'.$entity['model'];
$stubVariables['model_variable'] = Str::of($entity['model'])->camel();
$stubVariables['modelPolicy'] = "{$entity['model']}Policy";

Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Concerns/CanManipulateFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected function copyStubToApp(string $stub, string $targetPath, array $replac
$filesystem = new Filesystem;

if (! $this->fileExists($stubPath = base_path("stubs/filament/{$stub}.stub"))) {
$stubPath = __DIR__ . "/../../../stubs/{$stub}.stub";
$stubPath = __DIR__."/../../../stubs/{$stub}.stub";
}

$stub = Str::of($filesystem->get($stubPath));
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/MakeShieldDoctorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class MakeShieldDoctorCommand extends Command
public function handle(): int
{
AboutCommand::add('Filament Shield', [
'Auth Provider' => Utils::getAuthProviderFQCN() . '|' . static::authProviderConfigured(),
'Auth Provider' => Utils::getAuthProviderFQCN().'|'.static::authProviderConfigured(),
'Resource' => Utils::isResourcePublished() ? '<fg=red;options=bold>PUBLISHED</>' : '<fg=green;options=bold>NOT PUBLISHED</>',
'Resource Slug' => Utils::getResourceSlug(),
'Resource Sort' => Utils::getResourceNavigationSort(),
Expand Down
8 changes: 4 additions & 4 deletions src/Commands/MakeShieldGenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,15 @@ protected function resourceInfo(array $resources): void
return [
'#' => $key + 1,
'Resource' => $resource['model'],
'Policy' => "{$resource['model']}Policy.php" . ($this->generatorOption !== 'permissions' ? '' : ''),
'Policy' => "{$resource['model']}Policy.php".($this->generatorOption !== 'permissions' ? '' : ''),
'Permissions' => implode(
',' . PHP_EOL,
','.PHP_EOL,
collect(
Utils::getResourcePermissionPrefixes($resource['fqcn'])
)->map(function ($permission) use ($resource) {
return $permission . '_' . $resource['resource'];
return $permission.'_'.$resource['resource'];
})->toArray()
) . ($this->generatorOption !== 'policies' ? '' : ''),
).($this->generatorOption !== 'policies' ? '' : ''),
];
})
);
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/MakeShieldInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ protected function install(bool $fresh = false): void
try {
Schema::disableForeignKeyConstraints();
DB::table('migrations')->where('migration', 'like', '%_create_permission_tables')->delete();
$this->getTables()->each(fn ($table) => DB::statement('DROP TABLE IF EXISTS ' . $table));
$this->getTables()->each(fn ($table) => DB::statement('DROP TABLE IF EXISTS '.$table));
Schema::enableForeignKeyConstraints();
} catch (Throwable $e) {
$this->components->info($e);
Expand Down
10 changes: 5 additions & 5 deletions src/Commands/MakeShieldPublishCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ public function handle(Filesystem $filesystem): int
}

$filesystem->ensureDirectoryExists($baseResourcePath);
$filesystem->copyDirectory(__DIR__ . '/../Resources', $baseResourcePath);
$filesystem->copyDirectory(__DIR__.'/../Resources', $baseResourcePath);

$currentNamespace = 'BezhanSalleh\\FilamentShield\\Resources';
$newNamespace = 'App\\Filament\\Resources\\Shield';

$this->replaceInFile($roleResourcePath, $currentNamespace, $newNamespace);
$this->replaceInFile($baseResourcePath . '/RoleResource/Pages/CreateRole.php', $currentNamespace, $newNamespace);
$this->replaceInFile($baseResourcePath . '/RoleResource/Pages/EditRole.php', $currentNamespace, $newNamespace);
$this->replaceInFile($baseResourcePath . '/RoleResource/Pages/ViewRole.php', $currentNamespace, $newNamespace);
$this->replaceInFile($baseResourcePath . '/RoleResource/Pages/ListRoles.php', $currentNamespace, $newNamespace);
$this->replaceInFile($baseResourcePath.'/RoleResource/Pages/CreateRole.php', $currentNamespace, $newNamespace);
$this->replaceInFile($baseResourcePath.'/RoleResource/Pages/EditRole.php', $currentNamespace, $newNamespace);
$this->replaceInFile($baseResourcePath.'/RoleResource/Pages/ViewRole.php', $currentNamespace, $newNamespace);
$this->replaceInFile($baseResourcePath.'/RoleResource/Pages/ListRoles.php', $currentNamespace, $newNamespace);

$this->components->info("Shield's Resource have been published successfully!");

Expand Down
42 changes: 21 additions & 21 deletions src/Concerns/CanCustomizeColumns.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,109 +6,109 @@

trait CanCustomizeColumns
{
protected int | string | array $checkboxListColumnSpan = 'full';
protected int|string|array $checkboxListColumnSpan = 'full';

protected int | string | array $checkboxListColumns = [
protected int|string|array $checkboxListColumns = [
'sm' => 2,
'lg' => 4,
];

protected int | string | array $gridColumns = 1;
protected int|string|array $gridColumns = 1;

protected int | string | array $resourceCheckboxListColumnSpan = 'full';
protected int|string|array $resourceCheckboxListColumnSpan = 'full';

protected int | string | array $resourceCheckboxListColumns = [
protected int|string|array $resourceCheckboxListColumns = [
'sm' => 2,
'lg' => 4,
];

protected int | string | array $sectionColumnSpan = 'full';
protected int|string|array $sectionColumnSpan = 'full';

protected int | string | array $sectionColumns = [
protected int|string|array $sectionColumns = [
'sm' => 2,
'lg' => 4,
];

public function checkboxListColumns(int | string | array $columns): static
public function checkboxListColumns(int|string|array $columns): static
{
$this->checkboxListColumns = $columns;

return $this;
}

public function checkboxListColumnSpan(int | string | array $columnSpan): static
public function checkboxListColumnSpan(int|string|array $columnSpan): static
{
$this->checkboxListColumnSpan = $columnSpan;

return $this;
}

public function gridColumns(int | string | array $columns): static
public function gridColumns(int|string|array $columns): static
{
$this->gridColumns = $columns;

return $this;
}

public function resourceCheckboxListColumns(int | string | array $columns): static
public function resourceCheckboxListColumns(int|string|array $columns): static
{
$this->resourceCheckboxListColumns = $columns;

return $this;
}

public function resourceCheckboxListColumnSpan(int | string | array $columnSpan): static
public function resourceCheckboxListColumnSpan(int|string|array $columnSpan): static
{
$this->resourceCheckboxListColumnSpan = $columnSpan;

return $this;
}

public function sectionColumns(int | string | array $columns): static
public function sectionColumns(int|string|array $columns): static
{
$this->sectionColumns = $columns;

return $this;
}

public function sectionColumnSpan(int | string | array $columnSpan): static
public function sectionColumnSpan(int|string|array $columnSpan): static
{
$this->sectionColumnSpan = $columnSpan;

return $this;
}

public function getCheckboxListColumns(): int | string | array
public function getCheckboxListColumns(): int|string|array
{
return $this->checkboxListColumns;
}

public function getCheckboxListColumnSpan(): int | string | array
public function getCheckboxListColumnSpan(): int|string|array
{
return $this->checkboxListColumnSpan;
}

public function getGridColumns(): int | string | array
public function getGridColumns(): int|string|array
{
return $this->gridColumns;
}

public function getResourceCheckboxListColumns(): int | string | array
public function getResourceCheckboxListColumns(): int|string|array
{
return $this->resourceCheckboxListColumns;
}

public function getResourceCheckboxListColumnSpan(): int | string | array
public function getResourceCheckboxListColumnSpan(): int|string|array
{
return $this->resourceCheckboxListColumnSpan;
}

public function getSectionColumns(): int | string | array
public function getSectionColumns(): int|string|array
{
return $this->sectionColumns;
}

public function getSectionColumnSpan(): int | string | array
public function getSectionColumnSpan(): int|string|array
{
return $this->sectionColumnSpan;
}
Expand Down
12 changes: 6 additions & 6 deletions src/FilamentShield.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function generateForResource(array $entity): void
collect($permissionPrefixes)
->each(function ($prefix) use ($entity, $permissions) {
$permissions->push(Utils::getPermissionModel()::firstOrCreate(
['name' => $prefix . '_' . $entity['resource']],
['name' => $prefix.'_'.$entity['resource']],
['guard_name' => Utils::getFilamentAuthGuard()]
));
});
Expand Down Expand Up @@ -94,7 +94,7 @@ public static function generateForWidget(string $widget): void
}
}

protected static function giveSuperAdminPermission(string | array | Collection $permissions): void
protected static function giveSuperAdminPermission(string|array|Collection $permissions): void
{
if (! Utils::isSuperAdminDefinedViaGate() && Utils::isSuperAdminEnabled()) {
$superAdmin = static::createRole();
Expand Down Expand Up @@ -301,10 +301,10 @@ public static function getLocalizedWidgetLabel(string $widget): string
return match (true) {
$widgetInstance instanceof TableWidget => (string) invade($widgetInstance)->makeTable()->getHeading(),
! ($widgetInstance instanceof TableWidget) && $widgetInstance instanceof Widget && method_exists($widgetInstance, 'getHeading') => (string) invade($widgetInstance)->getHeading(),
default => str($widget)
default => __(str($widget)
->afterLast('\\')
->headline()
->toString(),
->toString()),
};
}

Expand All @@ -318,7 +318,7 @@ protected function getDefaultPermissionIdentifier(string $resource): string
->replace('_', '::');
}

protected static function getWidgetInstanceFromWidgetConfiguration(string | WidgetConfiguration $widget): string
protected static function getWidgetInstanceFromWidgetConfiguration(string|WidgetConfiguration $widget): string
{
return $widget instanceof WidgetConfiguration
? $widget->widget
Expand All @@ -333,7 +333,7 @@ public function getAllResourcePermissions(): array
Utils::getResourcePermissionPrefixes($resourceEntity['fqcn'])
)
->flatMap(function ($permission) use ($resourceEntity) {
$name = $permission . '_' . $resourceEntity['resource'];
$name = $permission.'_'.$resourceEntity['resource'];
$permissionLabel = FilamentShieldPlugin::get()->hasLocalizedPermissionLabels()
? str(static::getLocalizedResourcePermissionLabel($permission))
->prepend(
Expand Down
4 changes: 2 additions & 2 deletions src/Resources/RoleResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public static function getResourceEntitiesSchema(): ?array
);

return Forms\Components\Section::make($sectionLabel)
->description(fn () => new HtmlString('<span style="word-break: break-word;">' . Utils::showModelPath($entity['fqcn']) . '</span>'))
->description(fn () => new HtmlString('<span style="word-break: break-word;">'.Utils::showModelPath($entity['fqcn']).'</span>'))
->compact()
->schema([
static::getCheckBoxListComponentForResource($entity),
Expand All @@ -233,7 +233,7 @@ public static function getResourcePermissionOptions(array $entity): array
{
return collect(Utils::getResourcePermissionPrefixes($entity['fqcn']))
->flatMap(function ($permission) use ($entity) {
$name = $permission . '_' . $entity['resource'];
$name = $permission.'_'.$entity['resource'];
$label = static::shield()->hasLocalizedPermissionLabels()
? FilamentShield::getLocalizedResourcePermissionLabel($permission)
: $name;
Expand Down
2 changes: 1 addition & 1 deletion src/Support/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,6 @@ protected static function isRolePolicyGenerated(): bool
{
$filesystem = new Filesystem;

return (bool) $filesystem->exists(app_path(static::getPolicyPath() . DIRECTORY_SEPARATOR . 'RolePolicy.php'));
return (bool) $filesystem->exists(app_path(static::getPolicyPath().DIRECTORY_SEPARATOR.'RolePolicy.php'));
}
}
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ protected function setUp(): void
parent::setUp();

Factory::guessFactoryNamesUsing(
fn (string $modelName) => 'BezhanSalleh\\FilamentShield\\Database\\Factories\\' . class_basename($modelName) . 'Factory'
fn (string $modelName) => 'BezhanSalleh\\FilamentShield\\Database\\Factories\\'.class_basename($modelName).'Factory'
);
}

Expand Down

0 comments on commit 25a8aff

Please sign in to comment.