32 private array $permissions = [];
38 private array $subscribers = [];
46 if(!$plugin->isEnabled()){
47 throw new PluginException(
"Plugin " . $plugin->getDescription()->getName() .
" is disabled");
51 public function getPlugin() :
Plugin{
65 return $this->permissions;
68 private function recalculatePermissibles() : void{
69 foreach($this->subscribers as $permissible){
70 $permissible->recalculatePermissions();
74 public function clearPermissions() : void{
75 $this->permissions = [];
76 $this->recalculatePermissibles();
83 foreach($permissions as $key => $value){
84 $this->permissions[$key] = $value;
86 $this->recalculatePermissibles();
93 foreach($permissions as $node){
94 unset($this->permissions[$node]);
96 $this->recalculatePermissibles();
99 public function setPermission(Permission|
string $name,
bool $value) : void{
100 $name = $name instanceof Permission ? $name->getName() : $name;
101 if(isset($this->permissions[$name])){
102 if($this->permissions[$name] === $value){
114 unset($this->permissions[$name]);
116 $this->permissions[$name] = $value;
117 $this->recalculatePermissibles();
120 public function unsetPermission(Permission|
string $name) : void{
121 $name = $name instanceof Permission ? $name->getName() : $name;
122 if(isset($this->permissions[$name])){
123 unset($this->permissions[$name]);
124 $this->recalculatePermissibles();
131 public function subscribePermissible(PermissibleInternal $permissible) : void{
132 $this->subscribers[spl_object_id($permissible)] = $permissible;
138 public function unsubscribePermissible(PermissibleInternal $permissible) : void{
139 unset($this->subscribers[spl_object_id($permissible)]);