This commit is contained in:
Dennis Eichhorn 2020-02-07 22:02:11 +01:00
parent 3c8a8c31d5
commit d0d77c9b9b
2 changed files with 40 additions and 2 deletions

View File

@ -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}
*/

View File

@ -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;
}
}