0 follower

Interface Yiisoft\Rbac\ManagerInterface

ExtendsYiisoft\Access\AccessCheckerInterface
Implemented byYiisoft\Rbac\Manager

An interface for managing RBAC entities (items, assignments, rules) with possibility to check user permissions.

Public Methods

Hide inherited methods

Method Description Defined By
addChild() Adds an item as a child of another item. Yiisoft\Rbac\ManagerInterface
addPermission() Yiisoft\Rbac\ManagerInterface
addRole() Yiisoft\Rbac\ManagerInterface
assign() Assigns a role or permission to a user. Yiisoft\Rbac\ManagerInterface
canAddChild() Checks the possibility of adding a child to a parent. Yiisoft\Rbac\ManagerInterface
getChildRoles() Returns child roles of the role specified. Depth isn't limited. Yiisoft\Rbac\ManagerInterface
getDefaultRoleNames() Returns default role names. Yiisoft\Rbac\ManagerInterface
getDefaultRoles() Returns default roles. Yiisoft\Rbac\ManagerInterface
getGuestRole() Get a guest role. Yiisoft\Rbac\ManagerInterface
getGuestRoleName() Get guest role name. Yiisoft\Rbac\ManagerInterface
getItemsByUserId() Returns the items that are assigned to the user via {@see assign()}. Yiisoft\Rbac\ManagerInterface
getPermission() Yiisoft\Rbac\ManagerInterface
getPermissionsByRoleName() Returns all permissions that the specified role represents. Yiisoft\Rbac\ManagerInterface
getPermissionsByUserId() Returns all permissions that the user has. Yiisoft\Rbac\ManagerInterface
getRole() Yiisoft\Rbac\ManagerInterface
getRolesByUserId() Returns the roles that are assigned to the user via {@see assign()}. Yiisoft\Rbac\ManagerInterface
getUserIdsByRoleName() Returns all user IDs assigned to the role specified. Yiisoft\Rbac\ManagerInterface
hasChild() Returns a value indicating whether the child already exists for the parent. Yiisoft\Rbac\ManagerInterface
hasChildren() Returns whether named parent has children. Yiisoft\Rbac\ManagerInterface
removeChild() Removes a child from its parent. Yiisoft\Rbac\ManagerInterface
removeChildren() Removes all children form their parent. Yiisoft\Rbac\ManagerInterface
removePermission() Yiisoft\Rbac\ManagerInterface
removeRole() Yiisoft\Rbac\ManagerInterface
revoke() Revokes a role or a permission from a user. Yiisoft\Rbac\ManagerInterface
revokeAll() Revokes all roles and permissions from a user. Yiisoft\Rbac\ManagerInterface
setDefaultRoleNames() Set default role names. Yiisoft\Rbac\ManagerInterface
setGuestRoleName() Set guest role name. Yiisoft\Rbac\ManagerInterface
updatePermission() Yiisoft\Rbac\ManagerInterface
updateRole() Yiisoft\Rbac\ManagerInterface

Method Details

Hide inherited methods

addChild() public abstract method

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;

            
addPermission() public abstract method

public abstract self addPermission ( Yiisoft\Rbac\Permission $permission )
$permission Yiisoft\Rbac\Permission
throws Yiisoft\Rbac\Exception\ItemAlreadyExistsException

                public function addPermission(Permission $permission): self;

            
addRole() public abstract method

public abstract self addRole ( Yiisoft\Rbac\Role $role )
$role Yiisoft\Rbac\Role
throws Yiisoft\Rbac\Exception\ItemAlreadyExistsException

                public function addRole(Role $role): self;

            
assign() public abstract method

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 null, current time is used.

throws InvalidArgumentException
  • If an item with the given name is not found.
  • During the attempt of assigning permissions directly when it's disabled.

                public function assign(string $itemName, int|Stringable|string $userId, ?int $createdAt = null): self;

            
canAddChild() public abstract method

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;

            
getChildRoles() public abstract method

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 $roleName.

                public function getChildRoles(string $roleName): array;

            
getDefaultRoleNames() public abstract method

Returns default role names.

public abstract string[] getDefaultRoleNames ( )
return string[]

Default role names.

                public function getDefaultRoleNames(): array;

            
getDefaultRoles() public abstract method

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;

            
getGuestRole() public abstract method

Get a guest role.

public abstract Yiisoft\Rbac\Role|null getGuestRole ( )
return Yiisoft\Rbac\Role|null

Guest role or null if the name was not set.

throws InvalidArgumentException

When a role was not found.

                public function getGuestRole(): ?Role;

            
getGuestRoleName() public abstract method

Get guest role name.

public abstract string|null getGuestRoleName ( )
return string|null

The guest role name or null if it was not set.

                public function getGuestRoleName(): ?string;

            
getItemsByUserId() public abstract method

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;

            
getPermission() public abstract method

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

The permission name.

                public function getPermission(string $name): ?Permission;

            
getPermissionsByRoleName() public abstract method

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;

            
getPermissionsByUserId() public abstract method

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;

            
getRole() public abstract method

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

The role name.

                public function getRole(string $name): ?Role;

            
getRolesByUserId() public abstract method

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;

            
getUserIdsByRoleName() public abstract method

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;

            
hasChild() public abstract method

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 $child is already a child of $parent

                public function hasChild(string $parentName, string $childName): bool;

            
hasChildren() public abstract method

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;

            
removeChild() public abstract method

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;

            
removeChildren() public abstract method

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;

            
removePermission() public abstract method

public abstract self removePermission ( string $name )
$name string

The permission name.

                public function removePermission(string $name): self;

            
removeRole() public abstract method

public abstract self removeRole ( string $name )
$name string

The role name.

                public function removeRole(string $name): self;

            
revoke() public abstract method

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;

            
revokeAll() public abstract method

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;

            
setDefaultRoleNames() public abstract method

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;

            
setGuestRoleName() public abstract method

Set guest role name.

public abstract self setGuestRoleName ( string|null $name )
$name string|null

The guest role name.

                public function setGuestRoleName(?string $name): self;

            
updatePermission() public abstract method

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;

            
updateRole() public abstract method

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;