Abstract Class Yiisoft\Rbac\SimpleItemsStorage
| Inheritance | Yiisoft\Rbac\SimpleItemsStorage |
|---|---|
| Implements | Yiisoft\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[]} |
Protected Properties
| Property | Type | Description | Defined By |
|---|---|---|---|
| $children | array | Yiisoft\Rbac\SimpleItemsStorage | |
| $items | array | Yiisoft\Rbac\SimpleItemsStorage |
Public Methods
Property Details
Method Details
| public add( Yiisoft\Rbac\Permission|Yiisoft\Rbac\Role $item ): void | ||
| $item | Yiisoft\Rbac\Permission|Yiisoft\Rbac\Role | |
public function add(Permission|Role $item): void
{
$this->items[$item->getName()] = $item;
}
| public addChild( string $parentName, string $childName ): void | ||
| $parentName | string | |
| $childName | string | |
public function addChild(string $parentName, string $childName): void
{
$this->children[$parentName][$childName] = $this->items[$childName];
}
| public clearPermissions( ): void |
public function clearPermissions(): void
{
$this->removeItemsByType(Item::TYPE_PERMISSION);
}
| public clearRoles( ): void |
public function clearRoles(): void
{
$this->removeItemsByType(Item::TYPE_ROLE);
}
| public exists( string $name ): boolean | ||
| $name | string | |
public function exists(string $name): bool
{
return array_key_exists($name, $this->items);
}
| public get( string $name ): Yiisoft\Rbac\Permission|Yiisoft\Rbac\Role|null | ||
| $name | string | |
public function get(string $name): Permission|Role|null
{
return $this->items[$name] ?? null;
}
| public getAllChildPermissions( string|array $names ): array | ||
| $names | string|array | |
public function getAllChildPermissions(string|array $names): array
{
$result = [];
$this->getAllChildrenInternal($names, $result);
return $this->filterPermissions($result);
}
| public getAllChildRoles( string|array $names ): array | ||
| $names | string|array | |
public function getAllChildRoles(string|array $names): array
{
$result = [];
$this->getAllChildrenInternal($names, $result);
return $this->filterRoles($result);
}
| public getAllChildren( string|array $names ): array | ||
| $names | string|array | |
public function getAllChildren(string|array $names): array
{
$result = [];
$this->getAllChildrenInternal($names, $result);
return $result;
}
| public getByNames( array $names ): array | ||
| $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),
);
}
| public getDirectChildren( string $name ): array | ||
| $name | string | |
public function getDirectChildren(string $name): array
{
return $this->children[$name] ?? [];
}
| public getHierarchy( string $name ): array | ||
| $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;
}
| public getParents( string $name ): array | ||
| $name | string | |
public function getParents(string $name): array
{
$result = [];
$this->fillParentsRecursive($name, $result);
return $result;
}
| public getPermission( string $name ): Yiisoft\Rbac\Permission|null | ||
| $name | string | |
public function getPermission(string $name): ?Permission
{
return $this->getItemsByType(Item::TYPE_PERMISSION)[$name] ?? null;
}
| public getPermissions( ): array |
public function getPermissions(): array
{
return $this->getItemsByType(Item::TYPE_PERMISSION);
}
| public getPermissionsByNames( array $names ): array | ||
| $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);
},
);
}
| public getRole( string $name ): Yiisoft\Rbac\Role|null | ||
| $name | string | |
public function getRole(string $name): ?Role
{
return $this->getItemsByType(Item::TYPE_ROLE)[$name] ?? null;
}
| public getRoles( ): array |
public function getRoles(): array
{
return $this->getItemsByType(Item::TYPE_ROLE);
}
| public getRolesByNames( array $names ): array | ||
| $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);
},
);
}
| public hasChild( string $parentName, string $childName ): boolean | ||
| $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;
}
| public hasChildren( string $name ): boolean | ||
| $name | string | |
public function hasChildren(string $name): bool
{
return isset($this->children[$name]);
}
| public hasDirectChild( string $parentName, string $childName ): boolean | ||
| $parentName | string | |
| $childName | string | |
public function hasDirectChild(string $parentName, string $childName): bool
{
return isset($this->children[$parentName][$childName]);
}
| public remove( string $name ): void | ||
| $name | string | |
public function remove(string $name): void
{
$this->clearChildrenFromItem($name);
$this->removeItemByName($name);
}
| public removeChild( string $parentName, string $childName ): void | ||
| $parentName | string | |
| $childName | string | |
public function removeChild(string $parentName, string $childName): void
{
unset($this->children[$parentName][$childName]);
}
| public removeChildren( string $parentName ): void | ||
| $parentName | string | |
public function removeChildren(string $parentName): void
{
unset($this->children[$parentName]);
}
| public roleExists( string $name ): boolean | ||
| $name | string | |
public function roleExists(string $name): bool
{
return isset($this->getItemsByType(Item::TYPE_ROLE)[$name]);
}
| public update( string $name, Yiisoft\Rbac\Permission|Yiisoft\Rbac\Role $item ): void | ||
| $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);
}
Signup or Login in order to comment.