*/ private array $abilities = []; /** @var array */ private array $resourceTypes = []; public function __construct() { $this->define('users.manage', 'Benutzer verwalten', 'System'); $this->define('roles.manage', 'Rollen und Rechte verwalten', 'System'); $this->define('identity.manage', 'Anmeldung (Microsoft Entra ID) einrichten', 'System'); $this->define('plugins.manage', 'Plugins verwalten und installieren', 'System'); $this->define('appearance.manage', 'Erscheinungsbild und Schnellzugriffe', 'System'); $this->define('updates.manage', 'Aktualisierungen, Lizenz und Systemzustand', 'System'); $this->define('mail.manage', 'E-Mail-Versand einrichten', 'System'); $this->define('ai.manage', 'KI-Assistent einrichten', 'System'); $this->define('feedback.send', 'Rückmeldungen an den Hersteller senden', 'System'); $this->define('media.manage', 'Mediathek verwalten: ersetzen, löschen, aufräumen', 'Mediathek', portal: true); } /** * @param bool $portal Recht wird vollständig im Portal ausgeübt (Redaktion) – öffnet nicht das Backend */ public function define(string $ability, string $label, string $group, ?string $resource = null, bool $portal = false): void { $this->abilities[$ability] = ['label' => $label, 'group' => $group, 'resource' => $resource, 'portal' => $portal]; } /** * Braucht dieses Recht das Backend (/admin)? Nur-Portal-Rechte und unbekannte * (z. B. von deaktivierten Plugins) nicht. */ public function needsBackend(string $ability): bool { return isset($this->abilities[$ability]) && ! $this->abilities[$ability]['portal']; } public function isPortalOnly(string $ability): bool { return (bool) ($this->abilities[$ability]['portal'] ?? false); } /** * Objekttyp, auf den sich Rechte beziehen können (z. B. „news_category“). * * Hierarchische Typen (z. B. Seiten) geben $descendants an: Rechte mit * „inkl. Unterobjekten“ gelten dann auch für alle Nachfahren. * * @param callable(): array $options ID => Bezeichnung * @param (callable(list): list)|null $descendants IDs => IDs aller Nachfahren */ public function resourceType(string $type, string $label, callable $options, ?callable $descendants = null): void { $this->resourceTypes[$type] = ['label' => $label, 'options' => $options, 'descendants' => $descendants]; } public function isHierarchical(?string $type): bool { return $type !== null && isset($this->resourceTypes[$type]['descendants']); } /** * @return array */ public function all(): array { return $this->abilities; } /** * @return array */ public function global(): array { return array_filter($this->abilities, fn (array $a) => $a['resource'] === null); } /** * @return array */ public function forResource(string $type): array { return array_filter($this->abilities, fn (array $a) => $a['resource'] === $type); } /** * @return array */ public function resourceTypes(): array { return $this->resourceTypes; } public function exists(string $ability): bool { return isset($this->abilities[$ability]); } public function label(string $ability): string { return $this->abilities[$ability]['label'] ?? $ability; } }