Abstract Class yii\rbac\BaseManager
Inheritance | yii\rbac\BaseManager » yii\base\Component » yii\base\Object |
---|---|
Implements | yii\base\Configurable, yii\rbac\ManagerInterface |
Subclasses | lispa\amos\core\rbac\AuthManager, lispa\amos\core\rbac\DbManagerCached, yii\rbac\DbManager, yii\rbac\PhpManager |
Available since version | 2.0 |
Source Code | https://github.com/yiisoft/yii2/blob/master/framework/rbac/BaseManager.php |
BaseManager is a base class implementing yii\rbac\ManagerInterface for RBAC management.
For more details and usage information on DbManager, see the guide article on security authorization.
Public Properties
Property | Type | Description | Defined By |
---|---|---|---|
$behaviors | yii\base\Behavior[] | List of behaviors attached to this component | yii\base\Component |
$defaultRoleInstances | yii\rbac\Role[] | Default roles. | yii\rbac\BaseManager |
$defaultRoles | array | A list of role names that are assigned to every user automatically without calling assign(). | yii\rbac\BaseManager |
$permissions | yii\rbac\Permission[] | All permissions in the system. | yii\rbac\BaseManager |
$roles | yii\rbac\Role[] | All roles in the system. | yii\rbac\BaseManager |
$rules | yii\rbac\Rule[] | The rules indexed by the rule names | yii\rbac\ManagerInterface |
Public Methods
Method | Description | Defined By |
---|---|---|
__call() | Calls the named method which is not a class method. | yii\base\Component |
__clone() | This method is called after the object is created by cloning an existing one. | yii\base\Component |
__construct() | Constructor. | yii\base\Object |
__get() | Returns the value of a component property. | yii\base\Component |
__isset() | Checks if a property is set, i.e. defined and not null. | yii\base\Component |
__set() | Sets the value of a component property. | yii\base\Component |
__unset() | Sets a component property to be null. | yii\base\Component |
add() | Adds a role, permission or rule to the RBAC system. | yii\rbac\BaseManager |
addChild() | Adds an item as a child of another item. | yii\rbac\ManagerInterface |
assign() | Assigns a role to a user. | yii\rbac\ManagerInterface |
attachBehavior() | Attaches a behavior to this component. | yii\base\Component |
attachBehaviors() | Attaches a list of behaviors to the component. | yii\base\Component |
behaviors() | Returns a list of behaviors that this component should behave as. | yii\base\Component |
canAddChild() | Checks the possibility of adding a child to parent | yii\rbac\ManagerInterface |
canGetProperty() | Returns a value indicating whether a property can be read. | yii\base\Component |
canSetProperty() | Returns a value indicating whether a property can be set. | yii\base\Component |
className() | Returns the fully qualified name of this class. | yii\base\Object |
createPermission() | Creates a new Permission object. | yii\rbac\BaseManager |
createRole() | Creates a new Role object. | yii\rbac\BaseManager |
detachBehavior() | Detaches a behavior from the component. | yii\base\Component |
detachBehaviors() | Detaches all behaviors from the component. | yii\base\Component |
ensureBehaviors() | Makes sure that the behaviors declared in behaviors() are attached to this component. | yii\base\Component |
getAssignment() | Returns the assignment information regarding a role and a user. | yii\rbac\ManagerInterface |
getAssignments() | Returns all role assignment information for the specified user. | yii\rbac\ManagerInterface |
getBehavior() | Returns the named behavior object. | yii\base\Component |
getBehaviors() | Returns all behaviors attached to this component. | yii\base\Component |
getChildRoles() | Returns child roles of the role specified. Depth isn't limited. | yii\rbac\ManagerInterface |
getChildren() | Returns the child permissions and/or roles. | yii\rbac\ManagerInterface |
getDefaultRoleInstances() | Returns defaultRoles as array of Role objects | yii\rbac\BaseManager |
getPermission() | Returns the named permission. | yii\rbac\BaseManager |
getPermissions() | Returns all permissions in the system. | yii\rbac\BaseManager |
getPermissionsByRole() | Returns all permissions that the specified role represents. | yii\rbac\ManagerInterface |
getPermissionsByUser() | Returns all permissions that the user has. | yii\rbac\ManagerInterface |
getRole() | Returns the named role. | yii\rbac\BaseManager |
getRoles() | Returns all roles in the system. | yii\rbac\BaseManager |
getRolesByUser() | Returns the roles that are assigned to the user via assign(). | yii\rbac\ManagerInterface |
getRule() | Returns the rule of the specified name. | yii\rbac\ManagerInterface |
getRules() | Returns all rules available in the system. | yii\rbac\ManagerInterface |
getUserIdsByRole() | Returns all user IDs assigned to the role specified. | yii\rbac\ManagerInterface |
hasChild() | Returns a value indicating whether the child already exists for the parent. | yii\rbac\ManagerInterface |
hasEventHandlers() | Returns a value indicating whether there is any handler attached to the named event. | yii\base\Component |
hasMethod() | Returns a value indicating whether a method is defined. | yii\base\Component |
hasProperty() | Returns a value indicating whether a property is defined for this component. | yii\base\Component |
init() | Initializes the object. | yii\base\Object |
off() | Detaches an existing event handler from this component. | yii\base\Component |
on() | Attaches an event handler to an event. | yii\base\Component |
remove() | Removes a role, permission or rule from the RBAC system. | yii\rbac\BaseManager |
removeAll() | Removes all authorization data, including roles, permissions, rules, and assignments. | yii\rbac\ManagerInterface |
removeAllAssignments() | Removes all role assignments. | yii\rbac\ManagerInterface |
removeAllPermissions() | Removes all permissions. | yii\rbac\ManagerInterface |
removeAllRoles() | Removes all roles. | yii\rbac\ManagerInterface |
removeAllRules() | Removes all rules. | yii\rbac\ManagerInterface |
removeChild() | Removes a child from its parent. | yii\rbac\ManagerInterface |
removeChildren() | Removed all children form their parent. | yii\rbac\ManagerInterface |
revoke() | Revokes a role from a user. | yii\rbac\ManagerInterface |
revokeAll() | Revokes all roles from a user. | yii\rbac\ManagerInterface |
trigger() | Triggers an event. | yii\base\Component |
update() | Updates the specified role, permission or rule in the system. | yii\rbac\BaseManager |
Protected Methods
Method | Description | Defined By |
---|---|---|
addItem() | Adds an auth item to the RBAC system. | yii\rbac\BaseManager |
addRule() | Adds a rule to the RBAC system. | yii\rbac\BaseManager |
executeRule() | Executes the rule associated with the specified auth item. | yii\rbac\BaseManager |
getItem() | Returns the named auth item. | yii\rbac\BaseManager |
getItems() | Returns the items of the specified type. | yii\rbac\BaseManager |
hasNoAssignments() | Checks whether array of $assignments is empty and $defaultRoles property is empty as well | yii\rbac\BaseManager |
removeItem() | Removes an auth item from the RBAC system. | yii\rbac\BaseManager |
removeRule() | Removes a rule from the RBAC system. | yii\rbac\BaseManager |
updateItem() | Updates an auth item in the RBAC system. | yii\rbac\BaseManager |
updateRule() | Updates a rule to the RBAC system. | yii\rbac\BaseManager |
Property Details
Default roles. The array is indexed by the role names
A list of role names that are assigned to every user automatically without calling assign().
All permissions in the system. The array is indexed by the permission names.
All roles in the system. The array is indexed by the role names.
Method Details
Adds a role, permission or rule to the RBAC system.
public boolean add ( $object ) | ||
$object | yii\rbac\Role|yii\rbac\Permission|yii\rbac\Rule | |
return | boolean | 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) |
Adds an auth item to the RBAC system.
protected abstract boolean addItem ( $item ) | ||
$item | yii\rbac\Item | The item to add |
return | boolean | Whether the auth item 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) |
Adds a rule to the RBAC system.
protected abstract boolean addRule ( $rule ) | ||
$rule | yii\rbac\Rule | The rule to add |
return | boolean | Whether the rule is successfully added to the system |
---|---|---|
throws | Exception | if data validation or saving fails (such as the name of the rule is not unique) |
Creates 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.
public yii\rbac\Permission createPermission ( $name ) | ||
$name | string | The permission name |
return | yii\rbac\Permission | The new Permission object |
---|
Creates 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.
public yii\rbac\Role createRole ( $name ) | ||
$name | string | The role name |
return | yii\rbac\Role | The new Role object |
---|
Executes 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 yii\rbac\Rule::execute().
protected boolean executeRule ( $user, $item, $params ) | ||
$user | string|integer | The user ID. This should be either an integer or a string representing the unique identifier of a user. See yii\web\User::$id. |
$item | yii\rbac\Item | The auth item that needs to execute its rule |
$params | array | Parameters passed to yii\rbac\CheckAccessInterface::checkAccess() and will be passed to the rule |
return | boolean | The return value of yii\rbac\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. |
Returns defaultRoles as array of Role objects
public yii\rbac\Role[] getDefaultRoleInstances ( ) | ||
return | yii\rbac\Role[] | Default roles. The array is indexed by the role names |
---|
Returns the named auth item.
protected abstract yii\rbac\Item getItem ( $name ) | ||
$name | string | The auth item name. |
return | yii\rbac\Item | The auth item corresponding to the specified name. Null is returned if no such item. |
---|
Returns the items of the specified type.
protected abstract yii\rbac\Item[] getItems ( $type ) | ||
$type | integer | The auth item type (either yii\rbac\Item::TYPE_ROLE or yii\rbac\Item::TYPE_PERMISSION |
return | yii\rbac\Item[] | The auth items of the specified type. |
---|
Returns the named permission.
public null|yii\rbac\Permission getPermission ( $name ) | ||
$name | string | The permission name. |
return | null|yii\rbac\Permission | The permission corresponding to the specified name. Null is returned if no such permission. |
---|
Returns all permissions in the system.
public yii\rbac\Permission[] getPermissions ( ) | ||
return | yii\rbac\Permission[] | All permissions in the system. The array is indexed by the permission names. |
---|
Returns the named role.
public null|yii\rbac\Role getRole ( $name ) | ||
$name | string | The role name. |
return | null|yii\rbac\Role | The role corresponding to the specified name. Null is returned if no such role. |
---|
Returns all roles in the system.
public yii\rbac\Role[] getRoles ( ) | ||
return | yii\rbac\Role[] | All roles in the system. The array is indexed by the role names. |
---|
Checks whether array of $assignments is empty and $defaultRoles property is empty as well
protected boolean hasNoAssignments ( array $assignments ) | ||
$assignments | yii\rbac\Assignment[] | Array of user's assignments |
return | boolean | Whether array of $assignments is empty and $defaultRoles property is empty as well |
---|
Removes a role, permission or rule from the RBAC system.
public boolean remove ( $object ) | ||
$object | yii\rbac\Role|yii\rbac\Permission|yii\rbac\Rule | |
return | boolean | Whether the role, permission or rule is successfully removed |
---|
Removes an auth item from the RBAC system.
protected abstract boolean removeItem ( $item ) | ||
$item | yii\rbac\Item | The item to remove |
return | boolean | Whether the role or permission is successfully removed |
---|---|---|
throws | Exception | if data validation or saving fails (such as the name of the role or permission is not unique) |
Removes a rule from the RBAC system.
protected abstract boolean removeRule ( $rule ) | ||
$rule | yii\rbac\Rule | The rule to remove |
return | boolean | Whether the rule is successfully removed |
---|---|---|
throws | Exception | if data validation or saving fails (such as the name of the rule is not unique) |
Updates the specified role, permission or rule in the system.
public boolean update ( $name, $object ) | ||
$name | string | The old name of the role, permission or rule |
$object | yii\rbac\Role|yii\rbac\Permission|yii\rbac\Rule | |
return | boolean | 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) |
Updates an auth item in the RBAC system.
protected abstract boolean updateItem ( $name, $item ) | ||
$name | string | The name of the item being updated |
$item | yii\rbac\Item | The updated item |
return | boolean | Whether the auth item is successfully updated |
---|---|---|
throws | Exception | if data validation or saving fails (such as the name of the role or permission is not unique) |
Updates a rule to the RBAC system.
protected abstract boolean updateRule ( $name, $rule ) | ||
$name | string | The name of the rule being updated |
$rule | yii\rbac\Rule | The updated rule |
return | boolean | Whether the rule is successfully updated |
---|---|---|
throws | Exception | if data validation or saving fails (such as the name of the rule is not unique) |