53 lines
1.3 KiB
PHP
53 lines
1.3 KiB
PHP
|
<?php declare(strict_types=1);
|
||
|
|
||
|
namespace App\Enums;
|
||
|
|
||
|
enum Permission: string
|
||
|
{
|
||
|
case Role = 'role';
|
||
|
|
||
|
public function getPermissions(): array
|
||
|
{
|
||
|
return $this->getBasePermissions();
|
||
|
}
|
||
|
|
||
|
public function getTitle(): string
|
||
|
{
|
||
|
return __('permissions.' . $this->name);
|
||
|
}
|
||
|
|
||
|
public function formatValue(string $permission): string
|
||
|
{
|
||
|
return $this->value . '.' . $permission;
|
||
|
}
|
||
|
|
||
|
public static function toArrayList(): array
|
||
|
{
|
||
|
$permissions = [];
|
||
|
foreach (self::cases() as $permissionEnum) {
|
||
|
foreach ($permissionEnum->getPermissions() as $permissionName => $permissionTitle) {
|
||
|
$name = $permissionEnum->formatValue($permissionName);
|
||
|
$title = $permissionEnum->getTitle() . ' - ' . $permissionTitle;
|
||
|
$permissions[$name] = $title;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return $permissions;
|
||
|
}
|
||
|
|
||
|
public static function toArrayListCodes(): array
|
||
|
{
|
||
|
return \array_keys(self::toArrayList());
|
||
|
}
|
||
|
|
||
|
private function getBasePermissions(): array
|
||
|
{
|
||
|
return [
|
||
|
'view' => __('permissions.Allowed to watch'),
|
||
|
'create' => __('permissions.Allowed to create'),
|
||
|
'update' => __('permissions.Allowed to edit'),
|
||
|
'delete' => __('permissions.Allowed to delete'),
|
||
|
];
|
||
|
}
|
||
|
}
|