0 follower

Abstract Class Yiisoft\Rbac\SimpleItemsStorage

InheritanceYiisoft\Rbac\SimpleItemsStorage
ImplementsYiisoft\Rbac\ItemsStorageInterface

Psalm Types

Name Value
RawItem array{type: \Yiisoft\Rbac\Item::TYPE_*, name: string, description?: string, rule_name?: string, created_at?: integer, updated_at?: integer, children?: string[]}

Property Details

Hide inherited properties

$children protected property
protected array $children = []
$items protected property
protected array $items = []

Method Details

Hide inherited methods

add() public method

public void add ( Yiisoft\Rbac\Permission|Yiisoft\Rbac\Role $item )
$item Yiisoft\Rbac\Permission|Yiisoft\Rbac\Role

                public function add(Permission|Role $item): void
{
    $this->items[$item->getName()] = $item;
}

            
addChild() public method

public void addChild ( string $parentName, string $childName )
$parentName string
$childName string

                public function addChild(string $parentName, string $childName): void
{
    $this->children[$parentName][$childName] = $this->items[$childName];
}

            
clear() public method

public void clear ( )

                public function clear(): void
{
    $this->children = [];
    $this->items = [];
}

            
clearPermissions() public method

public void clearPermissions ( )

                public function clearPermissions(): void
{
    $this->removeItemsByType(Item::TYPE_PERMISSION);
}

            
clearRoles() public method

public void clearRoles ( )

                public function clearRoles(): void
{
    $this->removeItemsByType(Item::TYPE_ROLE);
}

            
exists() public method

public boolean exists ( string $name )
$name string

                public function exists(string $name): bool
{
    return array_key_exists($name, $this->items);
}

            
get() public method

public Yiisoft\Rbac\Permission|Yiisoft\Rbac\Role|null get ( string $name )
$name string

                public function get(string $name): Permission|Role|null
{
    return $this->items[$name] ?? null;
}

            
getAll() public method

public array getAll ( )

                public function getAll(): array
{
    return $this->items;
}

            
getAllChildPermissions() public method

public array getAllChildPermissions ( string|array $names )
$names string|array

                public function getAllChildPermissions(string|array $names): array
{
    $result = [];
    $this->getAllChildrenInternal($names, $result);
    return $this->filterPermissions($result);
}

            
getAllChildRoles() public method

public array getAllChildRoles ( string|array $names )
$names string|array

                public function getAllChildRoles(string|array $names): array
{
    $result = [];
    $this->getAllChildrenInternal($names, $result);
    return $this->filterRoles($result);
}

            
getAllChildren() public method

public array getAllChildren ( string|array $names )
$names string|array

                public function getAllChildren(string|array $names): array
{
    $result = [];
    $this->getAllChildrenInternal($names, $result);
    return $result;
}

            
getByNames() public method

public array getByNames ( array $names )
$names array

                public function getByNames(array $names): array
{
    return array_filter(
        $this->getAll(),
        static fn(Item $item): bool => in_array($item->getName(), $names, strict: true),
    );
}

            
getDirectChildren() public method

public array getDirectChildren ( string $name )
$name string

                public function getDirectChildren(string $name): array
{
    return $this->children[$name] ?? [];
}

            
getHierarchy() public method

public array getHierarchy ( string $name )
$name string

                public function getHierarchy(string $name): array
{
    if (!array_key_exists($name, $this->items)) {
        return [];
    }
    $result = [$name => ['item' => $this->items[$name], 'children' => []]];
    $this->fillHierarchyRecursive($name, $result);
    return $result;
}

            
getParents() public method

public array getParents ( string $name )
$name string

                public function getParents(string $name): array
{
    $result = [];
    $this->fillParentsRecursive($name, $result);
    return $result;
}

            
getPermission() public method

public Yiisoft\Rbac\Permission|null getPermission ( string $name )
$name string

                public function getPermission(string $name): ?Permission
{
    return $this->getItemsByType(Item::TYPE_PERMISSION)[$name] ?? null;
}

            
getPermissions() public method

public array getPermissions ( )

                public function getPermissions(): array
{
    return $this->getItemsByType(Item::TYPE_PERMISSION);
}

            
getPermissionsByNames() public method

public array getPermissionsByNames ( array $names )
$names array

                public function getPermissionsByNames(array $names): array
{
    return array_filter(
        $this->getAll(),
        static function (Permission|Role $item) use ($names): bool {
            return $item instanceof Permission && in_array($item->getName(), $names, strict: true);
        },
    );
}

            
getRole() public method

public Yiisoft\Rbac\Role|null getRole ( string $name )
$name string

                public function getRole(string $name): ?Role
{
    return $this->getItemsByType(Item::TYPE_ROLE)[$name] ?? null;
}

            
getRoles() public method

public array getRoles ( )

                public function getRoles(): array
{
    return $this->getItemsByType(Item::TYPE_ROLE);
}

            
getRolesByNames() public method

public array getRolesByNames ( array $names )
$names array

                public function getRolesByNames(array $names): array
{
    return array_filter(
        $this->getAll(),
        static function (Permission|Role $item) use ($names): bool {
            return $item instanceof Role && in_array($item->getName(), $names, strict: true);
        },
    );
}

            
hasChild() public method

public boolean hasChild ( string $parentName, string $childName )
$parentName string
$childName string

                public function hasChild(string $parentName, string $childName): bool
{
    if ($parentName === $childName) {
        return true;
    }
    $children = $this->getDirectChildren($parentName);
    if (empty($children)) {
        return false;
    }
    foreach ($children as $groupChild) {
        if ($this->hasChild($groupChild->getName(), $childName)) {
            return true;
        }
    }
    return false;
}

            
hasChildren() public method

public boolean hasChildren ( string $name )
$name string

                public function hasChildren(string $name): bool
{
    return isset($this->children[$name]);
}

            
hasDirectChild() public method

public boolean hasDirectChild ( string $parentName, string $childName )
$parentName string
$childName string

                public function hasDirectChild(string $parentName, string $childName): bool
{
    return isset($this->children[$parentName][$childName]);
}

            
remove() public method

public void remove ( string $name )
$name string

                public function remove(string $name): void
{
    $this->clearChildrenFromItem($name);
    $this->removeItemByName($name);
}

            
removeChild() public method

public void removeChild ( string $parentName, string $childName )
$parentName string
$childName string

                public function removeChild(string $parentName, string $childName): void
{
    unset($this->children[$parentName][$childName]);
}

            
removeChildren() public method

public void removeChildren ( string $parentName )
$parentName string

                public function removeChildren(string $parentName): void
{
    unset($this->children[$parentName]);
}

            
roleExists() public method

public boolean roleExists ( string $name )
$name string

                public function roleExists(string $name): bool
{
    return isset($this->getItemsByType(Item::TYPE_ROLE)[$name]);
}

            
update() public method

public void update ( string $name, Yiisoft\Rbac\Permission|Yiisoft\Rbac\Role $item )
$name string
$item Yiisoft\Rbac\Permission|Yiisoft\Rbac\Role

                public function update(string $name, Permission|Role $item): void
{
    if ($item->getName() !== $name) {
        $this->updateItemName($name, $item);
        $this->removeItemByName($name);
    }
    $this->add($item);
}