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 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;
}
| 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];
}
| public void clearPermissions ( ) |
public function clearPermissions(): void
{
$this->removeItemsByType(Item::TYPE_PERMISSION);
}
| public void clearRoles ( ) |
public function clearRoles(): void
{
$this->removeItemsByType(Item::TYPE_ROLE);
}
| public boolean exists ( string $name ) | ||
| $name | string | |
public function exists(string $name): bool
{
return array_key_exists($name, $this->items);
}
| 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;
}
| 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);
}
| 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);
}
| public array getAllChildren ( string|array $names ) | ||
| $names | string|array | |
public function getAllChildren(string|array $names): array
{
$result = [];
$this->getAllChildrenInternal($names, $result);
return $result;
}
| 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),
);
}
| public array getDirectChildren ( string $name ) | ||
| $name | string | |
public function getDirectChildren(string $name): array
{
return $this->children[$name] ?? [];
}
| 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;
}
| public array getParents ( string $name ) | ||
| $name | string | |
public function getParents(string $name): array
{
$result = [];
$this->fillParentsRecursive($name, $result);
return $result;
}
| public Yiisoft\Rbac\Permission|null getPermission ( string $name ) | ||
| $name | string | |
public function getPermission(string $name): ?Permission
{
return $this->getItemsByType(Item::TYPE_PERMISSION)[$name] ?? null;
}
| public array getPermissions ( ) |
public function getPermissions(): array
{
return $this->getItemsByType(Item::TYPE_PERMISSION);
}
| 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);
},
);
}
| public Yiisoft\Rbac\Role|null getRole ( string $name ) | ||
| $name | string | |
public function getRole(string $name): ?Role
{
return $this->getItemsByType(Item::TYPE_ROLE)[$name] ?? null;
}
| public array getRoles ( ) |
public function getRoles(): array
{
return $this->getItemsByType(Item::TYPE_ROLE);
}
| 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);
},
);
}
| 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;
}
| public boolean hasChildren ( string $name ) | ||
| $name | string | |
public function hasChildren(string $name): bool
{
return isset($this->children[$name]);
}
| 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]);
}
| public void remove ( string $name ) | ||
| $name | string | |
public function remove(string $name): void
{
$this->clearChildrenFromItem($name);
$this->removeItemByName($name);
}
| public void removeChild ( string $parentName, string $childName ) | ||
| $parentName | string | |
| $childName | string | |
public function removeChild(string $parentName, string $childName): void
{
unset($this->children[$parentName][$childName]);
}
| public void removeChildren ( string $parentName ) | ||
| $parentName | string | |
public function removeChildren(string $parentName): void
{
unset($this->children[$parentName]);
}
| public boolean roleExists ( string $name ) | ||
| $name | string | |
public function roleExists(string $name): bool
{
return isset($this->getItemsByType(Item::TYPE_ROLE)[$name]);
}
| 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);
}
Signup or Login in order to comment.