32 private static ?
self $instance =
null;
35 if(self::$instance ===
null){
36 self::$instance =
new self();
39 return self::$instance;
46 protected array $permissions = [];
51 protected array $permSubs = [];
53 public function getPermission(
string $name) : ?
Permission{
54 return $this->permissions[$name] ??
null;
57 public function addPermission(
Permission $permission) :
bool{
58 if(!isset($this->permissions[$permission->getName()])){
59 $this->permissions[$permission->getName()] = $permission;
67 public function removePermission(
Permission|
string $permission) :
void{
69 unset($this->permissions[$permission->getName()]);
71 unset($this->permissions[$permission]);
80 if(!isset($this->permSubs[$permission])){
81 $this->permSubs[$permission] = [];
83 $this->permSubs[$permission][spl_object_id($permissible)] = $permissible;
91 if(isset($this->permSubs[$permission][spl_object_id($permissible)])){
92 if(count($this->permSubs[$permission]) === 1){
93 unset($this->permSubs[$permission]);
95 unset($this->permSubs[$permission][spl_object_id($permissible)]);
105 foreach(
Utils::promoteKeys($this->permSubs) as $permission => $subs){
106 if(count($subs) === 1 && isset($subs[spl_object_id($permissible)])){
107 unset($this->permSubs[$permission]);
109 unset($this->permSubs[$permission][spl_object_id($permissible)]);
120 return $this->permSubs[$permission] ?? [];
127 return $this->permissions;
130 public function clearPermissions() : void{
131 $this->permissions = [];