36 private array $permissions = [];
42 private array $subscribers = [];
50 if(!$plugin->isEnabled()){
51 throw new PluginException(
"Plugin " . $plugin->getDescription()->getName() .
" is disabled");
55 public function getPlugin() :
Plugin{
70 return $this->permissions;
73 private function recalculatePermissibles() : void{
74 foreach($this->subscribers as $permissible){
75 $permissible->recalculatePermissions();
79 public function clearPermissions() : void{
80 $this->permissions = [];
81 $this->recalculatePermissibles();
89 foreach(
Utils::stringifyKeys($permissions) as $key => $value){
90 $this->permissions[$key] = $value;
92 $this->recalculatePermissibles();
99 foreach($permissions as $node){
100 unset($this->permissions[$node]);
102 $this->recalculatePermissibles();
105 public function setPermission(Permission|
string $name,
bool $value) : void{
106 $name = $name instanceof Permission ? $name->getName() : $name;
107 if(isset($this->permissions[$name])){
108 if($this->permissions[$name] === $value){
120 unset($this->permissions[$name]);
122 $this->permissions[$name] = $value;
123 $this->recalculatePermissibles();
126 public function unsetPermission(Permission|
string $name) : void{
127 $name = $name instanceof Permission ? $name->getName() : $name;
128 if(isset($this->permissions[$name])){
129 unset($this->permissions[$name]);
130 $this->recalculatePermissibles();
137 public function subscribePermissible(PermissibleInternal $permissible) : void{
138 $this->subscribers[spl_object_id($permissible)] = $permissible;
144 public function unsubscribePermissible(PermissibleInternal $permissible) : void{
145 unset($this->subscribers[spl_object_id($permissible)]);