Interface Yiisoft\Rbac\ManagerInterface
| Extends | Yiisoft\Access\AccessCheckerInterface |
|---|---|
| Implemented by | Yiisoft\Rbac\Manager |
An interface for managing RBAC entities (items, assignments, rules) with possibility to check user permissions.
Public Methods
Method Details
Adds an item as a child of another item.
| public abstract self addChild ( string $parentName, string $childName ) | ||
| $parentName | string |
The name of the parent item. |
| $childName | string |
The name of the child item. |
| throws | RuntimeException | |
|---|---|---|
| throws | InvalidArgumentException | |
public function addChild(string $parentName, string $childName): self;
| public abstract self addPermission ( Yiisoft\Rbac\Permission $permission ) | ||
| $permission | Yiisoft\Rbac\Permission | |
| throws | Yiisoft\Rbac\Exception\ItemAlreadyExistsException | |
|---|---|---|
public function addPermission(Permission $permission): self;
| public abstract self addRole ( Yiisoft\Rbac\Role $role ) | ||
| $role | Yiisoft\Rbac\Role | |
| throws | Yiisoft\Rbac\Exception\ItemAlreadyExistsException | |
|---|---|---|
public function addRole(Role $role): self;
Assigns a role or permission to a user.
| public abstract self assign ( string $itemName, integer|string|\Stringable $userId, integer|null $createdAt = null ) | ||
| $itemName | string |
Name of the role or the permission to be assigned. |
| $userId | integer|string|\Stringable |
The user ID. |
| $createdAt | integer|null |
UNIX timestamp representing assignment creation time. When |
| throws | InvalidArgumentException |
|
|---|---|---|
public function assign(string $itemName, int|Stringable|string $userId, ?int $createdAt = null): self;
Checks the possibility of adding a child to a parent.
| public abstract boolean canAddChild ( string $parentName, string $childName ) | ||
| $parentName | string |
The name of the parent item. |
| $childName | string |
The name of the child item to be added to the hierarchy. |
| return | boolean |
Whether it is possible to add the child to the parent. |
|---|---|---|
public function canAddChild(string $parentName, string $childName): bool;
Returns child roles of the role specified. Depth isn't limited.
| public abstract Yiisoft\Rbac\Role[] getChildRoles ( string $roleName ) | ||
| $roleName | string |
Name of the role to get child roles for. |
| return | Yiisoft\Rbac\Role[] |
Child roles. The array is indexed by the role names. |
|---|---|---|
| throws | InvalidArgumentException |
If the role was not found by |
public function getChildRoles(string $roleName): array;
Returns default role names.
| public abstract string[] getDefaultRoleNames ( ) | ||
| return | string[] |
Default role names. |
|---|---|---|
public function getDefaultRoleNames(): array;
Returns default roles.
| public abstract Yiisoft\Rbac\Role[] getDefaultRoles ( ) | ||
| return | Yiisoft\Rbac\Role[] |
Default roles. The array is indexed by the role names. |
|---|---|---|
| throws | Yiisoft\Rbac\Exception\DefaultRolesNotFoundException |
When at least 1 of the default roles was not found. |
public function getDefaultRoles(): array;
Get a guest role.
| public abstract Yiisoft\Rbac\Role|null getGuestRole ( ) | ||
| return | Yiisoft\Rbac\Role|null |
Guest role or |
|---|---|---|
| throws | InvalidArgumentException |
When a role was not found. |
public function getGuestRole(): ?Role;
Get guest role name.
| public abstract string|null getGuestRoleName ( ) | ||
| return | string|null |
The guest role name or |
|---|---|---|
public function getGuestRoleName(): ?string;
Returns the items that are assigned to the user via {@see assign()}.
| public abstract array getItemsByUserId ( integer|string|\Stringable $userId ) | ||
| $userId | integer|string|\Stringable |
The user ID. |
| return | array |
All items directly assigned to the user. The array is indexed by the item names. |
|---|---|---|
public function getItemsByUserId(int|Stringable|string $userId): array;
| public abstract Yiisoft\Rbac\Permission|null getPermission ( string $name ) | ||
| $name | string |
The permission name. |
public function getPermission(string $name): ?Permission;
Returns all permissions that the specified role represents.
| public abstract Yiisoft\Rbac\Permission[] getPermissionsByRoleName ( string $roleName ) | ||
| $roleName | string |
The role name. |
| return | Yiisoft\Rbac\Permission[] |
All permissions that the role represents. The array is indexed by the permission names. |
|---|---|---|
public function getPermissionsByRoleName(string $roleName): array;
Returns all permissions that the user has.
| public abstract Yiisoft\Rbac\Permission[] getPermissionsByUserId ( integer|string|\Stringable $userId ) | ||
| $userId | integer|string|\Stringable |
The user ID. |
| return | Yiisoft\Rbac\Permission[] |
All permissions that the user has. The array is indexed by the permission names. |
|---|---|---|
public function getPermissionsByUserId(int|Stringable|string $userId): array;
| public abstract Yiisoft\Rbac\Role|null getRole ( string $name ) | ||
| $name | string |
The role name. |
public function getRole(string $name): ?Role;
Returns the roles that are assigned to the user via {@see assign()}.
| public abstract Yiisoft\Rbac\Role[] getRolesByUserId ( integer|string|\Stringable $userId ) | ||
| $userId | integer|string|\Stringable |
The user ID. |
| return | Yiisoft\Rbac\Role[] |
All roles directly assigned to the user. The array is indexed by the role names. |
|---|---|---|
public function getRolesByUserId(int|Stringable|string $userId): array;
Returns all user IDs assigned to the role specified.
| public abstract array getUserIdsByRoleName ( string $roleName ) | ||
| $roleName | string |
The role name. |
| return | array |
Array of user ID strings. |
|---|---|---|
public function getUserIdsByRoleName(string $roleName): array;
Returns a value indicating whether the child already exists for the parent.
| public abstract boolean hasChild ( string $parentName, string $childName ) | ||
| $parentName | string |
The name of the parent item. |
| $childName | string |
The name of the child item. |
| return | boolean |
Whether |
|---|---|---|
public function hasChild(string $parentName, string $childName): bool;
Returns whether named parent has children.
| public abstract boolean hasChildren ( string $parentName ) | ||
| $parentName | string |
The parent name. |
| return | boolean |
Whether named parent has children. |
|---|---|---|
public function hasChildren(string $parentName): bool;
Removes a child from its parent.
Note, the child item is not deleted. Only the parent-child relationship is removed.
| public abstract self removeChild ( string $parentName, string $childName ) | ||
| $parentName | string |
The name of the parent item. |
| $childName | string |
The name of the child item. |
public function removeChild(string $parentName, string $childName): self;
Removes all children form their parent.
Note, the children items are not deleted. Only the parent-child relationships are removed.
| public abstract self removeChildren ( string $parentName ) | ||
| $parentName | string |
The name of the parent item. |
public function removeChildren(string $parentName): self;
| public abstract self removePermission ( string $name ) | ||
| $name | string |
The permission name. |
public function removePermission(string $name): self;
| public abstract self removeRole ( string $name ) | ||
| $name | string |
The role name. |
public function removeRole(string $name): self;
Revokes a role or a permission from a user.
| public abstract self revoke ( string $itemName, integer|string|\Stringable $userId ) | ||
| $itemName | string |
The name of the role or permission to be revoked. |
| $userId | integer|string|\Stringable |
The user ID. |
public function revoke(string $itemName, int|Stringable|string $userId): self;
Revokes all roles and permissions from a user.
| public abstract self revokeAll ( integer|string|\Stringable $userId ) | ||
| $userId | integer|string|\Stringable |
The user ID. |
public function revokeAll(int|Stringable|string $userId): self;
Set default role names.
| public abstract self setDefaultRoleNames ( array|Closure $roleNames ) | ||
| $roleNames | array|Closure |
Either array of role names or a closure returning it. |
| throws | InvalidArgumentException |
When role names is not a list of strings passed directly or resolved from a closure. |
|---|---|---|
public function setDefaultRoleNames(array|Closure $roleNames): self;
Set guest role name.
| public abstract self setGuestRoleName ( string|null $name ) | ||
| $name | string|null |
The guest role name. |
public function setGuestRoleName(?string $name): self;
| public abstract self updatePermission ( string $name, Yiisoft\Rbac\Permission $permission ) | ||
| $name | string |
The permission name. |
| $permission | Yiisoft\Rbac\Permission |
Permission instance with updated data. |
public function updatePermission(string $name, Permission $permission): self;
| public abstract self updateRole ( string $name, Yiisoft\Rbac\Role $role ) | ||
| $name | string |
The role name. |
| $role | Yiisoft\Rbac\Role |
Role instance with updated data. |
public function updateRole(string $name, Role $role): self;
Signup or Login in order to comment.