BaseManager
API reference › yii › rbac › BaseManager
2 subclasses
BaseManager is a base class implementing ManagerInterface for RBAC management.
For more details and usage information on DbManager, see the guide article on security authorization.
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$behaviors read-only | array<yii\<static>> | List of behaviors attached to this component. | yii\ |
$defaultRoleInstances read-only | Role[] | Default roles. | BaseManager |
$permissions read-only | Permission[] | All permissions in the system. | BaseManager |
$roles read-only | Role[] | All roles in the system. | BaseManager |
$rules read-only | Rule[] | The rules indexed by the rule names | ManagerInterface |
$defaultRoles protected | array | A list of role names that are assigned to every user automatically without calling assign(). Default: []. | BaseManager |
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | Constructor. | yii\ |
__call() | Calls the named method which is not a class method. | yii\ |
__clone() | This method is called after the object is created by cloning an existing one. | yii\ |
__get() | Returns the value of a component property. | yii\ |
__isset() | Checks if a property is set, i.e. defined and not null. | yii\ |
__set() | Sets the value of a component property. | yii\ |
__unset() | Sets a component property to be null. | yii\ |
add() | Adds a role, permission or rule to the RBAC system. | BaseManager |
addChild() abstract | Adds an item as a child of another item. | ManagerInterface |
assign() abstract | Assigns a role to a user. | ManagerInterface |
attachBehavior() | Attaches a behavior to this component. | yii\ |
attachBehaviors() | Attaches a list of behaviors to the component. | yii\ |
behaviors() | Returns a list of behaviors that this component should behave as. | yii\ |
canAddChild() abstract | Checks the possibility of adding a child to parent. | ManagerInterface |
canGetProperty() | Returns a value indicating whether a property can be read. | yii\ |
canSetProperty() | Returns a value indicating whether a property can be set. | yii\ |
className() static | Returns the fully qualified name of this class. | yii\ |
createPermission() | Creates a new Permission object. | BaseManager |
createRole() | Creates a new Role object. | BaseManager |
detachBehavior() | Detaches a behavior from the component. | yii\ |
detachBehaviors() | Detaches all behaviors from the component. | yii\ |
ensureBehaviors() | Makes sure that the behaviors declared in behaviors() are attached to this component. | yii\ |
getAssignment() abstract | Returns the assignment information regarding a role and a user. | ManagerInterface |
getAssignments() abstract | Returns all role assignment information for the specified user. | ManagerInterface |
getBehavior() | Returns the named behavior object. | yii\ |
getBehaviors() | Returns all behaviors attached to this component. | yii\ |
getChildren() abstract | Returns the child permissions and/or roles. | ManagerInterface |
getChildRoles() abstract | Returns child roles of the role specified. Depth isn’t limited. | ManagerInterface |
getDefaultRoleInstances() | Returns defaultRoles as array of Role objects. | BaseManager |
getDefaultRoles() | Get default roles | BaseManager |
getPermission() | Returns the named permission. | BaseManager |
getPermissions() | Returns all permissions in the system. | BaseManager |
getPermissionsByRole() abstract | Returns all permissions that the specified role represents. | ManagerInterface |
getPermissionsByUser() abstract | Returns all permissions that the user has. | ManagerInterface |
getRole() | Returns the named role. | BaseManager |
getRoles() | Returns all roles in the system. | BaseManager |
getRolesByUser() abstract | Returns the roles that are assigned to the user via assign(). | ManagerInterface |
getRule() abstract | Returns the rule of the specified name. | ManagerInterface |
getRules() abstract | Returns all rules available in the system. | ManagerInterface |
getUserIdsByRole() abstract | Returns all user IDs assigned to the role specified. | ManagerInterface |
hasChild() abstract | Returns a value indicating whether the child already exists for the parent. | ManagerInterface |
hasEventHandlers() | Returns a value indicating whether there is any handler attached to the named event. | yii\ |
hasMethod() | Returns a value indicating whether a method is defined. | yii\ |
hasProperty() | Returns a value indicating whether a property is defined for this component. | yii\ |
init() | Initializes the object. | yii\ |
off() | Detaches an existing event handler from this component. | yii\ |
on() | Attaches an event handler to an event. | yii\ |
remove() | Removes a role, permission or rule from the RBAC system. | BaseManager |
removeAll() abstract | Removes all authorization data, including roles, permissions, rules, and assignments. | ManagerInterface |
removeAllAssignments() abstract | Removes all role assignments. | ManagerInterface |
removeAllPermissions() abstract | Removes all permissions. | ManagerInterface |
removeAllRoles() abstract | Removes all roles. | ManagerInterface |
removeAllRules() abstract | Removes all rules. | ManagerInterface |
removeChild() abstract | Removes a child from its parent. | ManagerInterface |
removeChildren() abstract | Removed all children form their parent. | ManagerInterface |
revoke() abstract | Revokes a role from a user. | ManagerInterface |
revokeAll() abstract | Revokes all roles from a user. | ManagerInterface |
setDefaultRoles() | Set default roles | BaseManager |
trigger() | Triggers an event. | yii\ |
update() | Updates the specified role, permission or rule in the system. | BaseManager |
addItem() protected abstract | Adds an auth item to the RBAC system. | BaseManager |
addRule() protected abstract | Adds a rule to the RBAC system. | BaseManager |
executeRule() protected | Executes the rule associated with the specified auth item. | BaseManager |
getItem() protected abstract | Returns the named auth item. | BaseManager |
getItems() protected abstract | Returns the items of the specified type. | BaseManager |
hasNoAssignments() protected | Checks whether array of $assignments is empty and $defaultRoles property is empty as well. | BaseManager |
removeItem() protected abstract | Removes an auth item from the RBAC system. | BaseManager |
removeRule() protected abstract | Removes a rule from the RBAC system. | BaseManager |
updateItem() protected abstract | Updates an auth item in the RBAC system. | BaseManager |
updateRule() protected abstract | Updates a rule to the RBAC system. | BaseManager |
Property details
Section titled “Property details”$defaultRoleInstances
Section titled “$defaultRoleInstances ”public yii\rbac\Role[] $defaultRoleInstancesDefault roles.
The array is indexed by the role names.
Access
Read-only (virtual property).
$permissions
Section titled “$permissions ”public yii\rbac\Permission[] $permissionsAll permissions in the system.
The array is indexed by the permission names.
Access
Read-only (virtual property).
$roles
Section titled “$roles ”public yii\rbac\Role[] $rolesAll roles in the system.
The array is indexed by the role names.
Access
Read-only (virtual property).
$defaultRoles
Section titled “$defaultRoles ”protected array $defaultRoles = []A list of role names that are assigned to every user automatically without calling assign().
Note that these roles are applied to users, regardless of their state of authentication.
Method details
Section titled “Method details”add()
Section titled “add() ”public function add(mixed $object): boolAdds a role, permission or rule to the RBAC system.
Parameters
| Parameter | Type | Description |
|---|---|---|
$object | mixed |
Returns
bool: Whether the role, permission or rule is successfully added to the system
Throws
Exception: if data validation or saving fails (such as the name of the role or permission is not unique)
createPermission()
Section titled “createPermission() ”public function createPermission(mixed $name): yii\rbac\PermissionCreates a new Permission object.
Note that the newly created permission is not added to the RBAC system yet.
You must fill in the needed data and call add() to add it to the system.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | mixed | The permission name |
Returns
Permission: The new Permission object
createRole()
Section titled “createRole() ”public function createRole(mixed $name): yii\rbac\RoleCreates a new Role object.
Note that the newly created role is not added to the RBAC system yet.
You must fill in the needed data and call add() to add it to the system.
getDefaultRoleInstances()
Section titled “getDefaultRoleInstances() ”public function getDefaultRoleInstances(): yii\rbac\Role[]Returns defaultRoles as array of Role objects.
getDefaultRoles()
Section titled “getDefaultRoles() ”public function getDefaultRoles(): string[]Get default roles
Returns
string[]: Default roles
Since
2.0.14
getPermission()
Section titled “getPermission() ”public function getPermission(mixed $name): yii\rbac\Permission|nullReturns the named permission.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | mixed | The permission name. |
Returns
Permission|null: The permission corresponding to the specified name. Null is returned if no such permission.
getPermissions()
Section titled “getPermissions() ”public function getPermissions(): yii\rbac\Permission[]Returns all permissions in the system.
Returns
Permission[]: All permissions in the system. The array is indexed by the permission names.
getRole()
Section titled “getRole() ”public function getRole(mixed $name): yii\rbac\Role|nullReturns the named role.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | mixed | The role name. |
Returns
Role|null: The role corresponding to the specified name. Null is returned if no such role.
getRoles()
Section titled “getRoles() ”public function getRoles(): yii\rbac\Role[]Returns all roles in the system.
Returns
Role[]: All roles in the system. The array is indexed by the role names.
remove()
Section titled “remove() ”public function remove(mixed $object): boolRemoves a role, permission or rule from the RBAC system.
Parameters
| Parameter | Type | Description |
|---|---|---|
$object | mixed |
Returns
bool: Whether the role, permission or rule is successfully removed
setDefaultRoles()
Section titled “setDefaultRoles() ”public function setDefaultRoles(string[]|Closure $roles): mixedSet default roles
Parameters
| Parameter | Type | Description |
|---|---|---|
$roles | string[]|Closure | Either array of roles or a callable returning it |
Returns
mixed
Throws
yii\base\InvalidArgumentException: when $roles is neither array nor Closureyii\base\InvalidValueException: when Closure return is not an array
Since
2.0.14
update()
Section titled “update() ”public function update(mixed $name, mixed $object): boolUpdates the specified role, permission or rule in the system.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | mixed | The old name of the role, permission or rule |
$object | mixed |
Returns
bool: Whether the update is successful
Throws
Exception: if data validation or saving fails (such as the name of the role or permission is not unique)
addItem()
Section titled “addItem() ”abstract protected function addItem(yii\rbac\Item $item): boolAdds an auth item to the RBAC system.
addRule()
Section titled “addRule() ”abstract protected function addRule(yii\rbac\Rule $rule): boolAdds a rule to the RBAC system.
executeRule()
Section titled “executeRule() ”protected function executeRule(string|int $user, yii\rbac\Item $item, array $params): boolExecutes the rule associated with the specified auth item.
If the item does not specify a rule, this method will return true. Otherwise, it will
return the value of Rule::execute().
Parameters
| Parameter | Type | Description |
|---|---|---|
$user | string| | The user ID. This should be either an integer or a string representing the unique identifier of a user. See User::$id. |
$item | Item | The auth item that needs to execute its rule |
$params | array | Parameters passed to CheckAccessInterface::checkAccess() and will be passed to the rule |
Returns
bool: The return value of Rule::execute(). If the auth item does not specify a rule, true will be returned.
Throws
yii\base\InvalidConfigException: if the auth item has an invalid rule.
getItem()
Section titled “getItem() ”abstract protected function getItem(string $name): yii\rbac\Item|nullReturns the named auth item.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | The auth item name. |
Returns
Item|null: The auth item corresponding to the specified name. Null is returned if no such item.
getItems()
Section titled “getItems() ”abstract protected function getItems(yii\rbac\Item::TYPE_ROLE|yii\rbac\Item::TYPE_PERMISSION $type): ($type is yii\rbac\Item::TYPE_ROLE ? yii\rbac\Role[] : yii\rbac\Permission[])Returns the items of the specified type.
Parameters
| Parameter | Type | Description |
|---|---|---|
$type | Item::TYPE_ROLE|Item::TYPE_PERMISSION | The auth item type (either Item::TYPE_ROLE or Item::TYPE_PERMISSION |
Returns
($type is Item::TYPE_ROLE ? Role[] : Permission[]): The auth items of the specified type.
hasNoAssignments()
Section titled “hasNoAssignments() ”protected function hasNoAssignments(yii\rbac\Assignment[] $assignments): boolChecks whether array of $assignments is empty and $defaultRoles property is empty as well.
Parameters
| Parameter | Type | Description |
|---|---|---|
$assignments | Assignment[] | Array of user’s assignments |
Returns
bool: Whether array of $assignments is empty and $defaultRoles property is empty as well
Since
2.0.11
removeItem()
Section titled “removeItem() ”abstract protected function removeItem(yii\rbac\Item $item): boolRemoves an auth item from the RBAC system.
removeRule()
Section titled “removeRule() ”abstract protected function removeRule(yii\rbac\Rule $rule): boolRemoves a rule from the RBAC system.
updateItem()
Section titled “updateItem() ”abstract protected function updateItem(string $name, yii\rbac\Item $item): boolUpdates an auth item in the RBAC system.
updateRule()
Section titled “updateRule() ”abstract protected function updateRule(string $name, yii\rbac\Rule $rule): boolUpdates a rule to the RBAC system.