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 addChild( string $parentName, string $childName ): self | ||
| $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 addPermission( Yiisoft\Rbac\Permission $permission ): self | ||
| $permission | Yiisoft\Rbac\Permission | |
| throws | Yiisoft\Rbac\Exception\ItemAlreadyExistsException | |
|---|---|---|
public function addPermission(Permission $permission): self;
| public abstract addRole( Yiisoft\Rbac\Role $role ): self | ||
| $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 assign( string $itemName, integer|string|\Stringable $userId, integer|null $createdAt = null ): self | ||
| $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 canAddChild( string $parentName, string $childName ): boolean | ||
| $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 getChildRoles( string $roleName ): Yiisoft\Rbac\Role[] | ||
| $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 getDefaultRoleNames( ): string[] | ||
| return | string[] |
Default role names. |
|---|---|---|
public function getDefaultRoleNames(): array;
Returns default roles.
| public abstract getDefaultRoles( ): Yiisoft\Rbac\Role[] | ||
| 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 getGuestRole( ): Yiisoft\Rbac\Role|null | ||
| 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 getGuestRoleName( ): string|null | ||
| return | string|null |
The guest role name or |
|---|---|---|
public function getGuestRoleName(): ?string;
Returns the items that are assigned to the user via assign().
| public abstract getItemsByUserId( integer|string|\Stringable $userId ): array | ||
| $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 getPermission( string $name ): Yiisoft\Rbac\Permission|null | ||
| $name | string |
The permission name. |
public function getPermission(string $name): ?Permission;
Returns all permissions that the specified role represents.
| public abstract getPermissionsByRoleName( string $roleName ): Yiisoft\Rbac\Permission[] | ||
| $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 getPermissionsByUserId( integer|string|\Stringable $userId ): Yiisoft\Rbac\Permission[] | ||
| $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 getRole( string $name ): Yiisoft\Rbac\Role|null | ||
| $name | string |
The role name. |
public function getRole(string $name): ?Role;
Returns the roles that are assigned to the user via assign().
| public abstract getRolesByUserId( integer|string|\Stringable $userId ): Yiisoft\Rbac\Role[] | ||
| $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 getUserIdsByRoleName( string $roleName ): array | ||
| $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 hasChild( string $parentName, string $childName ): boolean | ||
| $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 hasChildren( string $parentName ): boolean | ||
| $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 removeChild( string $parentName, string $childName ): self | ||
| $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 removeChildren( string $parentName ): self | ||
| $parentName | string |
The name of the parent item. |
public function removeChildren(string $parentName): self;
| public abstract removePermission( string $name ): self | ||
| $name | string |
The permission name. |
public function removePermission(string $name): self;
| public abstract removeRole( string $name ): self | ||
| $name | string |
The role name. |
public function removeRole(string $name): self;
Revokes a role or a permission from a user.
| public abstract revoke( string $itemName, integer|string|\Stringable $userId ): self | ||
| $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 revokeAll( integer|string|\Stringable $userId ): self | ||
| $userId | integer|string|\Stringable |
The user ID. |
public function revokeAll(int|Stringable|string $userId): self;
Set default role names.
| public abstract setDefaultRoleNames( array|Closure $roleNames ): self | ||
| $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 setGuestRoleName( string|null $name ): self | ||
| $name | string|null |
The guest role name. |
public function setGuestRoleName(?string $name): self;
| public abstract updatePermission( string $name, Yiisoft\Rbac\Permission $permission ): self | ||
| $name | string |
The permission name. |
| $permission | Yiisoft\Rbac\Permission |
Permission instance with updated data. |
public function updatePermission(string $name, Permission $permission): self;
| public abstract updateRole( string $name, Yiisoft\Rbac\Role $role ): self | ||
| $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.