29 lines
653 B
PHP
29 lines
653 B
PHP
<?php
|
|
|
|
namespace App\Services\ACL;
|
|
|
|
use App\Domain\ACL\Role;
|
|
use Spatie\Permission\Models\Role as SpatieRole;
|
|
|
|
final class RoleService
|
|
{
|
|
private static array $roles = [];
|
|
|
|
private static function initCache(): void
|
|
{
|
|
if (empty(self::$roles)) {
|
|
self::$roles = SpatieRole::pluck('id', 'name')->toArray();
|
|
}
|
|
}
|
|
|
|
public static function select(): array
|
|
{
|
|
// self::initCache();
|
|
|
|
return collect(Role::cases())
|
|
// ->mapWithKeys(fn (Role $r) => [self::$roles[$r->value] => $r->name])
|
|
->mapWithKeys(fn (Role $r) => [$r->value => $r->name])
|
|
->toArray();
|
|
}
|
|
}
|