105 if(!$plugin->isEnabled()){
106 throw new PluginException(
"Plugin " . $plugin->getDescription()->getName() .
" is disabled");
110 $this->attachments[spl_object_id($result)] = $result;
111 if($name !==
null && $value !==
null){
112 $result->setPermission($name, $value);
115 $result->subscribePermissible($this);
117 $this->recalculatePermissions();
134 Timings::$permissibleCalculation->startTiming();
136 $permManager = PermissionManager::getInstance();
137 $permManager->unsubscribeFromAllPermissions($this);
138 $oldPermissions = $this->permissions;
139 $this->permissions = [];
141 foreach(Utils::stringifyKeys($this->rootPermissions) as $name => $isGranted){
142 $perm = $permManager->getPermission($name);
144 throw new \LogicException(
"Unregistered root permission $name");
147 $permManager->subscribeToPermission($name, $this);
148 $this->calculateChildPermissions($perm->getChildren(), !$isGranted,
null, $this->permissions[$name]);
151 foreach($this->attachments as $attachment){
152 $this->calculateChildPermissions($attachment->getPermissions(),
false, $attachment,
null);
156 Timings::$permissibleCalculationDiff->time(
function() use ($oldPermissions, &$diff) :
void{
157 foreach($this->permissions as $permissionAttachmentInfo){
158 $name = $permissionAttachmentInfo->getPermission();
159 if(!isset($oldPermissions[$name])){
160 $diff[$name] =
false;
161 }elseif($oldPermissions[$name]->getValue() !== $permissionAttachmentInfo->getValue()){
164 unset($oldPermissions[$name]);
167 foreach($oldPermissions as $permissionAttachmentInfo){
168 $diff[$permissionAttachmentInfo->getPermission()] = $permissionAttachmentInfo->getValue();
172 Timings::$permissibleCalculationCallback->time(
function() use ($diff) :
void{
173 if(count($diff) > 0){
174 foreach($this->permissionRecalculationCallbacks as $closure){
180 Timings::$permissibleCalculation->stopTiming();
188 private function calculateChildPermissions(array $children,
bool $invert, ?PermissionAttachment $attachment, ?PermissionAttachmentInfo $parent) : void{
193 $this->permissions[$name] =
new PermissionAttachmentInfo($name, $attachment, $value, $parent);
197 $this->calculateChildPermissions($perm->getChildren(), !$value, $attachment, $this->permissions[$name]);