> Person => gesperrte Kürzel (je Anfrage) */ private array $blocked = []; public function __construct(private readonly Settings $settings) {} /** * @return array> Kürzel => Rollen-IDs */ public function all(): array { return array_filter(array_map( fn ($ids) => array_values(array_unique(array_map('intval', (array) $ids))), (array) $this->settings->get(self::SETTING, []), )); } /** * @return list */ public function excludedRoles(string $slug): array { return $this->all()[$slug] ?? []; } /** * @param list $roleIds */ public function exclude(string $slug, array $roleIds): void { $all = $this->all(); $all[$slug] = array_values(array_unique(array_map('intval', $roleIds))); $this->settings->set(self::SETTING, array_filter($all)); $this->blocked = []; } public function allows(string $key, ?User $user): bool { return ! in_array(self::slugOf($key), $this->blockedFor($user), true); } /** * @return list */ public function blockedFor(?User $user): array { if (! $user) { return []; } return $this->blocked[$user->id] ??= (function () use ($user) { $all = $this->all(); if ($all === [] || $user->can('plugins.manage')) { return []; } $roleIds = array_map('intval', $user->permissions()->roleIds); return array_values(array_keys(array_filter($all, fn (array $ids) => array_intersect($ids, $roleIds) !== []))); })(); } public static function slugOf(string $key): string { return explode('.', $key, 2)[0]; } }