diff --git a/Account/PermissionAbstract.php b/Account/PermissionAbstract.php index 80908d035..dbcc8c8b8 100644 --- a/Account/PermissionAbstract.php +++ b/Account/PermissionAbstract.php @@ -416,6 +416,26 @@ class PermissionAbstract implements \JsonSerializable && ($this->permission | $permission) === $this->permission; } + /** + * Is equals. + * + * @param self $permission Permission + * + * @return bool Returns true if the permission is the same + * + * @since 1.0.0 + */ + public function isEqual(self $permission) : bool + { + return $this->unit === $permission->getUnit() + && $this->app === $permission->getApp() + && $this->module === $permission->getModule() + && $this->type === $permission->getType() + && $this->element === $permission->getElement() + && $this->component === $permission->getComponent() + && $this->permission === $permission->getPermission(); + } + /** * {@inheritdoc} */ diff --git a/Account/PermissionHandlingTrait.php b/Account/PermissionHandlingTrait.php index e9e5f982f..bb6272391 100644 --- a/Account/PermissionHandlingTrait.php +++ b/Account/PermissionHandlingTrait.php @@ -102,6 +102,24 @@ trait PermissionHandlingTrait ++$this->pLength; } + /** + * Remove permission. + * + * @param PermissionAbstract $permission Permission to remove + * + * @return void + * + * @since 1.0.0 + */ + public function removePermission(PermissionAbstract $permission) : void + { + foreach ($this->permissions as $key => $p) { + if ($p->isEqual($permission)) { + unset($this->permission[$key]); + } + } + } + /** * Get permissions. * @@ -142,8 +160,8 @@ trait PermissionHandlingTrait ) : bool { $app = $app !== null ? \strtolower($app) : $app; - for ($i = 0; $i < $this->pLength; ++$i) { - if ($this->permissions[$i]->hasPermission($permission, $unit, $app, $module, $type, $element, $component)) { + foreach ($this->permissions as $p) { + if ($p->hasPermission($permission, $unit, $app, $module, $type, $element, $component)) { return true; } }