# BaseManager

> BaseManager is a base class implementing yii\rbac\ManagerInterface for RBAC management.

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [rbac](/docs/api/yii/rbac/index.md) › BaseManager

| abstract class | `yii\rbac\BaseManager` |
| --- | --- |
| Extends | [`yii\base\Component`](/docs/api/yii/base/component/index.md) » [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| Implements | [`ManagerInterface`](/docs/api/yii/rbac/managerinterface/index.md), [`yii\base\Configurable`](/docs/api/yii/base/configurable/index.md) |
| Since | 2.0 |
| Source | [`framework/rbac/BaseManager.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/rbac/BaseManager.php#L30) |

2 subclasses:

- [`DbManager`](/docs/api/yii/rbac/dbmanager/index.md)
- [`PhpManager`](/docs/api/yii/rbac/phpmanager/index.md)

BaseManager is a base class implementing [`ManagerInterface`](/docs/api/yii/rbac/managerinterface/index.md) for RBAC management.

For more details and usage information on DbManager, see the [guide article on security authorization](/docs/guide/security-authorization/index.md).

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-behaviors"></span>[`$behaviors`](/docs/api/yii/base/component/index.md#property-behaviors) read-only | `array<`[`yii\base\Behavior`](/docs/api/yii/base/behavior/index.md)`<static>>` | List of behaviors attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`$defaultRoleInstances`](#property-defaultRoleInstances) read-only | [`Role`](/docs/api/yii/rbac/role/index.md)`[]` | Default roles. | `BaseManager` |
| [`$permissions`](#property-permissions) read-only | [`Permission`](/docs/api/yii/rbac/permission/index.md)`[]` | All permissions in the system. | `BaseManager` |
| [`$roles`](#property-roles) read-only | [`Role`](/docs/api/yii/rbac/role/index.md)`[]` | All roles in the system. | `BaseManager` |
| <span id="property-rules"></span>`$rules` read-only | [`Rule`](/docs/api/yii/rbac/rule/index.md)`[]` | The rules indexed by the rule names | [`ManagerInterface`](/docs/api/yii/rbac/managerinterface/index.md) |
| [`$defaultRoles`](#property-defaultRoles) protected | `array` | A list of role names that are assigned to every user automatically without calling [`assign()`](/docs/api/yii/rbac/managerinterface/index.md#method-assign). Default: `[]`. | `BaseManager` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| <span id="method-__construct"></span>[`__construct()`](/docs/api/yii/base/baseobject/index.md#method-__construct) | Constructor. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__call"></span>[`__call()`](/docs/api/yii/base/component/index.md#method-__call) | Calls the named method which is not a class method. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__clone"></span>[`__clone()`](/docs/api/yii/base/component/index.md#method-__clone) | This method is called after the object is created by cloning an existing one. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__get"></span>[`__get()`](/docs/api/yii/base/component/index.md#method-__get) | Returns the value of a component property. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__isset"></span>[`__isset()`](/docs/api/yii/base/component/index.md#method-__isset) | Checks if a property is set, i.e. defined and not null. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__set"></span>[`__set()`](/docs/api/yii/base/component/index.md#method-__set) | Sets the value of a component property. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__unset"></span>[`__unset()`](/docs/api/yii/base/component/index.md#method-__unset) | Sets a component property to be null. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`add()`](#method-add) | Adds a role, permission or rule to the RBAC system. | `BaseManager` |
| <span id="method-addChild"></span>[`addChild()`](/docs/api/yii/rbac/managerinterface/index.md#method-addChild) abstract | Adds an item as a child of another item. | [`ManagerInterface`](/docs/api/yii/rbac/managerinterface/index.md) |
| <span id="method-assign"></span>[`assign()`](/docs/api/yii/rbac/managerinterface/index.md#method-assign) abstract | Assigns a role to a user. | [`ManagerInterface`](/docs/api/yii/rbac/managerinterface/index.md) |
| <span id="method-attachBehavior"></span>[`attachBehavior()`](/docs/api/yii/base/component/index.md#method-attachBehavior) | Attaches a behavior to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-attachBehaviors"></span>[`attachBehaviors()`](/docs/api/yii/base/component/index.md#method-attachBehaviors) | Attaches a list of behaviors to the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-behaviors"></span>[`behaviors()`](/docs/api/yii/base/component/index.md#method-behaviors) | Returns a list of behaviors that this component should behave as. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-canAddChild"></span>[`canAddChild()`](/docs/api/yii/rbac/managerinterface/index.md#method-canAddChild) abstract | Checks the possibility of adding a child to parent. | [`ManagerInterface`](/docs/api/yii/rbac/managerinterface/index.md) |
| <span id="method-canGetProperty"></span>[`canGetProperty()`](/docs/api/yii/base/component/index.md#method-canGetProperty) | Returns a value indicating whether a property can be read. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-canSetProperty"></span>[`canSetProperty()`](/docs/api/yii/base/component/index.md#method-canSetProperty) | Returns a value indicating whether a property can be set. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-className"></span>[`className()`](/docs/api/yii/base/baseobject/index.md#method-className) static | Returns the fully qualified name of this class. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| [`createPermission()`](#method-createPermission) | Creates a new Permission object. | `BaseManager` |
| [`createRole()`](#method-createRole) | Creates a new Role object. | `BaseManager` |
| <span id="method-detachBehavior"></span>[`detachBehavior()`](/docs/api/yii/base/component/index.md#method-detachBehavior) | Detaches a behavior from the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-detachBehaviors"></span>[`detachBehaviors()`](/docs/api/yii/base/component/index.md#method-detachBehaviors) | Detaches all behaviors from the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-ensureBehaviors"></span>[`ensureBehaviors()`](/docs/api/yii/base/component/index.md#method-ensureBehaviors) | Makes sure that the behaviors declared in [`behaviors()`](/docs/api/yii/base/component/index.md#method-behaviors) are attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-getAssignment"></span>[`getAssignment()`](/docs/api/yii/rbac/managerinterface/index.md#method-getAssignment) abstract | Returns the assignment information regarding a role and a user. | [`ManagerInterface`](/docs/api/yii/rbac/managerinterface/index.md) |
| <span id="method-getAssignments"></span>[`getAssignments()`](/docs/api/yii/rbac/managerinterface/index.md#method-getAssignments) abstract | Returns all role assignment information for the specified user. | [`ManagerInterface`](/docs/api/yii/rbac/managerinterface/index.md) |
| <span id="method-getBehavior"></span>[`getBehavior()`](/docs/api/yii/base/component/index.md#method-getBehavior) | Returns the named behavior object. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-getBehaviors"></span>[`getBehaviors()`](/docs/api/yii/base/component/index.md#method-getBehaviors) | Returns all behaviors attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-getChildren"></span>[`getChildren()`](/docs/api/yii/rbac/managerinterface/index.md#method-getChildren) abstract | Returns the child permissions and/or roles. | [`ManagerInterface`](/docs/api/yii/rbac/managerinterface/index.md) |
| <span id="method-getChildRoles"></span>[`getChildRoles()`](/docs/api/yii/rbac/managerinterface/index.md#method-getChildRoles) abstract | Returns child roles of the role specified. Depth isn't limited. | [`ManagerInterface`](/docs/api/yii/rbac/managerinterface/index.md) |
| [`getDefaultRoleInstances()`](#method-getDefaultRoleInstances) | Returns defaultRoles as array of Role objects. | `BaseManager` |
| [`getDefaultRoles()`](#method-getDefaultRoles) | Get default roles | `BaseManager` |
| [`getPermission()`](#method-getPermission) | Returns the named permission. | `BaseManager` |
| [`getPermissions()`](#method-getPermissions) | Returns all permissions in the system. | `BaseManager` |
| <span id="method-getPermissionsByRole"></span>[`getPermissionsByRole()`](/docs/api/yii/rbac/managerinterface/index.md#method-getPermissionsByRole) abstract | Returns all permissions that the specified role represents. | [`ManagerInterface`](/docs/api/yii/rbac/managerinterface/index.md) |
| <span id="method-getPermissionsByUser"></span>[`getPermissionsByUser()`](/docs/api/yii/rbac/managerinterface/index.md#method-getPermissionsByUser) abstract | Returns all permissions that the user has. | [`ManagerInterface`](/docs/api/yii/rbac/managerinterface/index.md) |
| [`getRole()`](#method-getRole) | Returns the named role. | `BaseManager` |
| [`getRoles()`](#method-getRoles) | Returns all roles in the system. | `BaseManager` |
| <span id="method-getRolesByUser"></span>[`getRolesByUser()`](/docs/api/yii/rbac/managerinterface/index.md#method-getRolesByUser) abstract | Returns the roles that are assigned to the user via [`assign()`](/docs/api/yii/rbac/managerinterface/index.md#method-assign). | [`ManagerInterface`](/docs/api/yii/rbac/managerinterface/index.md) |
| <span id="method-getRule"></span>[`getRule()`](/docs/api/yii/rbac/managerinterface/index.md#method-getRule) abstract | Returns the rule of the specified name. | [`ManagerInterface`](/docs/api/yii/rbac/managerinterface/index.md) |
| <span id="method-getRules"></span>[`getRules()`](/docs/api/yii/rbac/managerinterface/index.md#method-getRules) abstract | Returns all rules available in the system. | [`ManagerInterface`](/docs/api/yii/rbac/managerinterface/index.md) |
| <span id="method-getUserIdsByRole"></span>[`getUserIdsByRole()`](/docs/api/yii/rbac/managerinterface/index.md#method-getUserIdsByRole) abstract | Returns all user IDs assigned to the role specified. | [`ManagerInterface`](/docs/api/yii/rbac/managerinterface/index.md) |
| <span id="method-hasChild"></span>[`hasChild()`](/docs/api/yii/rbac/managerinterface/index.md#method-hasChild) abstract | Returns a value indicating whether the child already exists for the parent. | [`ManagerInterface`](/docs/api/yii/rbac/managerinterface/index.md) |
| <span id="method-hasEventHandlers"></span>[`hasEventHandlers()`](/docs/api/yii/base/component/index.md#method-hasEventHandlers) | Returns a value indicating whether there is any handler attached to the named event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-hasMethod"></span>[`hasMethod()`](/docs/api/yii/base/component/index.md#method-hasMethod) | Returns a value indicating whether a method is defined. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-hasProperty"></span>[`hasProperty()`](/docs/api/yii/base/component/index.md#method-hasProperty) | Returns a value indicating whether a property is defined for this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-init"></span>[`init()`](/docs/api/yii/base/baseobject/index.md#method-init) | Initializes the object. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-off"></span>[`off()`](/docs/api/yii/base/component/index.md#method-off) | Detaches an existing event handler from this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-on"></span>[`on()`](/docs/api/yii/base/component/index.md#method-on) | Attaches an event handler to an event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`remove()`](#method-remove) | Removes a role, permission or rule from the RBAC system. | `BaseManager` |
| <span id="method-removeAll"></span>[`removeAll()`](/docs/api/yii/rbac/managerinterface/index.md#method-removeAll) abstract | Removes all authorization data, including roles, permissions, rules, and assignments. | [`ManagerInterface`](/docs/api/yii/rbac/managerinterface/index.md) |
| <span id="method-removeAllAssignments"></span>[`removeAllAssignments()`](/docs/api/yii/rbac/managerinterface/index.md#method-removeAllAssignments) abstract | Removes all role assignments. | [`ManagerInterface`](/docs/api/yii/rbac/managerinterface/index.md) |
| <span id="method-removeAllPermissions"></span>[`removeAllPermissions()`](/docs/api/yii/rbac/managerinterface/index.md#method-removeAllPermissions) abstract | Removes all permissions. | [`ManagerInterface`](/docs/api/yii/rbac/managerinterface/index.md) |
| <span id="method-removeAllRoles"></span>[`removeAllRoles()`](/docs/api/yii/rbac/managerinterface/index.md#method-removeAllRoles) abstract | Removes all roles. | [`ManagerInterface`](/docs/api/yii/rbac/managerinterface/index.md) |
| <span id="method-removeAllRules"></span>[`removeAllRules()`](/docs/api/yii/rbac/managerinterface/index.md#method-removeAllRules) abstract | Removes all rules. | [`ManagerInterface`](/docs/api/yii/rbac/managerinterface/index.md) |
| <span id="method-removeChild"></span>[`removeChild()`](/docs/api/yii/rbac/managerinterface/index.md#method-removeChild) abstract | Removes a child from its parent. | [`ManagerInterface`](/docs/api/yii/rbac/managerinterface/index.md) |
| <span id="method-removeChildren"></span>[`removeChildren()`](/docs/api/yii/rbac/managerinterface/index.md#method-removeChildren) abstract | Removed all children form their parent. | [`ManagerInterface`](/docs/api/yii/rbac/managerinterface/index.md) |
| <span id="method-revoke"></span>[`revoke()`](/docs/api/yii/rbac/managerinterface/index.md#method-revoke) abstract | Revokes a role from a user. | [`ManagerInterface`](/docs/api/yii/rbac/managerinterface/index.md) |
| <span id="method-revokeAll"></span>[`revokeAll()`](/docs/api/yii/rbac/managerinterface/index.md#method-revokeAll) abstract | Revokes all roles from a user. | [`ManagerInterface`](/docs/api/yii/rbac/managerinterface/index.md) |
| [`setDefaultRoles()`](#method-setDefaultRoles) | Set default roles | `BaseManager` |
| <span id="method-trigger"></span>[`trigger()`](/docs/api/yii/base/component/index.md#method-trigger) | Triggers an event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`update()`](#method-update) | Updates the specified role, permission or rule in the system. | `BaseManager` |
| [`addItem()`](#method-addItem) protected abstract | Adds an auth item to the RBAC system. | `BaseManager` |
| [`addRule()`](#method-addRule) protected abstract | Adds a rule to the RBAC system. | `BaseManager` |
| [`executeRule()`](#method-executeRule) protected | Executes the rule associated with the specified auth item. | `BaseManager` |
| [`getItem()`](#method-getItem) protected abstract | Returns the named auth item. | `BaseManager` |
| [`getItems()`](#method-getItems) protected abstract | Returns the items of the specified type. | `BaseManager` |
| [`hasNoAssignments()`](#method-hasNoAssignments) protected | Checks whether array of $assignments is empty and [`$defaultRoles`](/docs/api/yii/rbac/basemanager/index.md#property-defaultRoles) property is empty as well. | `BaseManager` |
| [`removeItem()`](#method-removeItem) protected abstract | Removes an auth item from the RBAC system. | `BaseManager` |
| [`removeRule()`](#method-removeRule) protected abstract | Removes a rule from the RBAC system. | `BaseManager` |
| [`updateItem()`](#method-updateItem) protected abstract | Updates an auth item in the RBAC system. | `BaseManager` |
| [`updateRule()`](#method-updateRule) protected abstract | Updates a rule to the RBAC system. | `BaseManager` |

## Property details

### $defaultRoleInstances <span id="property-defaultRoleInstances"></span>

```php
public yii\rbac\Role[] $defaultRoleInstances
```

Default roles.

The array is indexed by the role names.

**Access**

Read-only (virtual property).

### $permissions <span id="property-permissions"></span>

```php
public yii\rbac\Permission[] $permissions
```

All permissions in the system.

The array is indexed by the permission names.

**Access**

Read-only (virtual property).

### $roles <span id="property-roles"></span>

```php
public yii\rbac\Role[] $roles
```

All roles in the system.

The array is indexed by the role names.

**Access**

Read-only (virtual property).

### $defaultRoles <span id="property-defaultRoles"></span>

```php
protected array $defaultRoles = []
```

A list of role names that are assigned to every user automatically without calling [`assign()`](/docs/api/yii/rbac/managerinterface/index.md#method-assign).

Note that these roles are applied to users, regardless of their state of authentication.

## Method details

### add() <span id="method-add"></span>

```php
public function add(mixed $object): bool
```

Adds 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`](https://www.php.net/manual/en/class.exception.php): if data validation or saving fails (such as the name of the role or permission is not unique)

### createPermission() <span id="method-createPermission"></span>

```php
public function createPermission(mixed $name): yii\rbac\Permission
```

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()`](/docs/api/yii/rbac/basemanager/index.md#method-add) to add it to the system.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `mixed` | The permission name |

**Returns**

[`Permission`](/docs/api/yii/rbac/permission/index.md): The new Permission object

### createRole() <span id="method-createRole"></span>

```php
public function createRole(mixed $name): yii\rbac\Role
```

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()`](/docs/api/yii/rbac/basemanager/index.md#method-add) to add it to the system.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `mixed` | The role name |

**Returns**

[`Role`](/docs/api/yii/rbac/role/index.md): The new Role object

### getDefaultRoleInstances() <span id="method-getDefaultRoleInstances"></span>

```php
public function getDefaultRoleInstances(): yii\rbac\Role[]
```

Returns defaultRoles as array of Role objects.

**Returns**

[`Role`](/docs/api/yii/rbac/role/index.md)`[]`: Default roles. The array is indexed by the role names

**Since**

2.0.12

### getDefaultRoles() <span id="method-getDefaultRoles"></span>

```php
public function getDefaultRoles(): string[]
```

Get default roles

**Returns**

`string[]`: Default roles

**Since**

2.0.14

### getPermission() <span id="method-getPermission"></span>

```php
public function getPermission(mixed $name): yii\rbac\Permission|null
```

Returns the named permission.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `mixed` | The permission name. |

**Returns**

[`Permission`](/docs/api/yii/rbac/permission/index.md)`|null`: The permission corresponding to the specified name. Null is returned if no such permission.

### getPermissions() <span id="method-getPermissions"></span>

```php
public function getPermissions(): yii\rbac\Permission[]
```

Returns all permissions in the system.

**Returns**

[`Permission`](/docs/api/yii/rbac/permission/index.md)`[]`: All permissions in the system. The array is indexed by the permission names.

### getRole() <span id="method-getRole"></span>

```php
public function getRole(mixed $name): yii\rbac\Role|null
```

Returns the named role.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `mixed` | The role name. |

**Returns**

[`Role`](/docs/api/yii/rbac/role/index.md)`|null`: The role corresponding to the specified name. Null is returned if no such role.

### getRoles() <span id="method-getRoles"></span>

```php
public function getRoles(): yii\rbac\Role[]
```

Returns all roles in the system.

**Returns**

[`Role`](/docs/api/yii/rbac/role/index.md)`[]`: All roles in the system. The array is indexed by the role names.

### remove() <span id="method-remove"></span>

```php
public function remove(mixed $object): bool
```

Removes 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() <span id="method-setDefaultRoles"></span>

```php
public function setDefaultRoles(string[]|Closure $roles): mixed
```

Set default roles

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$roles` | `string[]\|`[`Closure`](https://www.php.net/manual/en/class.closure.php) | Either array of roles or a callable returning it |

**Returns**

`mixed`

**Throws**

- [`yii\base\InvalidArgumentException`](/docs/api/yii/base/invalidargumentexception/index.md): when $roles is neither array nor Closure
- [`yii\base\InvalidValueException`](/docs/api/yii/base/invalidvalueexception/index.md): when Closure return is not an array

**Since**

2.0.14

### update() <span id="method-update"></span>

```php
public function update(mixed $name, mixed $object): bool
```

Updates 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`](https://www.php.net/manual/en/class.exception.php): if data validation or saving fails (such as the name of the role or permission is not unique)

### addItem() <span id="method-addItem"></span>

```php
abstract protected function addItem(yii\rbac\Item $item): bool
```

Adds an auth item to the RBAC system.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$item` | [`Item`](/docs/api/yii/rbac/item/index.md) | The item to add |

**Returns**

`bool`: Whether the auth item is successfully added to the system

**Throws**

- [`Exception`](https://www.php.net/manual/en/class.exception.php): if data validation or saving fails (such as the name of the role or permission is not unique)

### addRule() <span id="method-addRule"></span>

```php
abstract protected function addRule(yii\rbac\Rule $rule): bool
```

Adds a rule to the RBAC system.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$rule` | [`Rule`](/docs/api/yii/rbac/rule/index.md) | The rule to add |

**Returns**

`bool`: Whether the rule is successfully added to the system

**Throws**

- [`Exception`](https://www.php.net/manual/en/class.exception.php): if data validation or saving fails (such as the name of the rule is not unique)

### executeRule() <span id="method-executeRule"></span>

```php
protected function executeRule(string|int $user, yii\rbac\Item $item, array $params): bool
```

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 [`Rule::execute()`](/docs/api/yii/rbac/rule/index.md#method-execute).

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$user` | `string\|int` | The user ID. This should be either an integer or a string representing the unique identifier of a user. See [`User::$id`](/docs/api/yii/web/user/index.md#property-id). |
| `$item` | [`Item`](/docs/api/yii/rbac/item/index.md) | The auth item that needs to execute its rule |
| `$params` | `array` | Parameters passed to [`CheckAccessInterface::checkAccess()`](/docs/api/yii/rbac/checkaccessinterface/index.md#method-checkAccess) and will be passed to the rule |

**Returns**

`bool`: The return value of [`Rule::execute()`](/docs/api/yii/rbac/rule/index.md#method-execute). If the auth item does not specify a rule, true will be returned.

**Throws**

- [`yii\base\InvalidConfigException`](/docs/api/yii/base/invalidconfigexception/index.md): if the auth item has an invalid rule.

### getItem() <span id="method-getItem"></span>

```php
abstract protected function getItem(string $name): yii\rbac\Item|null
```

Returns the named auth item.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | The auth item name. |

**Returns**

[`Item`](/docs/api/yii/rbac/item/index.md)`|null`: The auth item corresponding to the specified name. Null is returned if no such item.

### getItems() <span id="method-getItems"></span>

```php
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`](/docs/api/yii/rbac/item/index.md)`::TYPE_ROLE\|`[`Item`](/docs/api/yii/rbac/item/index.md)`::TYPE_PERMISSION` | The auth item type (either [`Item::TYPE_ROLE`](/docs/api/yii/rbac/item/index.md#const-TYPE_ROLE) or [`Item::TYPE_PERMISSION`](/docs/api/yii/rbac/item/index.md#const-TYPE_PERMISSION) |

**Returns**

`($type is` [`Item`](/docs/api/yii/rbac/item/index.md)`::TYPE_ROLE ?` [`Role`](/docs/api/yii/rbac/role/index.md)`[] :` [`Permission`](/docs/api/yii/rbac/permission/index.md)`[])`: The auth items of the specified type.

### hasNoAssignments() <span id="method-hasNoAssignments"></span>

```php
protected function hasNoAssignments(yii\rbac\Assignment[] $assignments): bool
```

Checks whether array of $assignments is empty and [`$defaultRoles`](/docs/api/yii/rbac/basemanager/index.md#property-defaultRoles) property is empty as well.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$assignments` | [`Assignment`](/docs/api/yii/rbac/assignment/index.md)`[]` | Array of user's assignments |

**Returns**

`bool`: Whether array of $assignments is empty and [`$defaultRoles`](/docs/api/yii/rbac/basemanager/index.md#property-defaultRoles) property is empty as well

**Since**

2.0.11

### removeItem() <span id="method-removeItem"></span>

```php
abstract protected function removeItem(yii\rbac\Item $item): bool
```

Removes an auth item from the RBAC system.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$item` | [`Item`](/docs/api/yii/rbac/item/index.md) | The item to remove |

**Returns**

`bool`: Whether the role or permission is successfully removed

**Throws**

- [`Exception`](https://www.php.net/manual/en/class.exception.php): if data validation or saving fails (such as the name of the role or permission is not unique)

### removeRule() <span id="method-removeRule"></span>

```php
abstract protected function removeRule(yii\rbac\Rule $rule): bool
```

Removes a rule from the RBAC system.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$rule` | [`Rule`](/docs/api/yii/rbac/rule/index.md) | The rule to remove |

**Returns**

`bool`: Whether the rule is successfully removed

**Throws**

- [`Exception`](https://www.php.net/manual/en/class.exception.php): if data validation or saving fails (such as the name of the rule is not unique)

### updateItem() <span id="method-updateItem"></span>

```php
abstract protected function updateItem(string $name, yii\rbac\Item $item): bool
```

Updates an auth item in the RBAC system.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | The name of the item being updated |
| `$item` | [`Item`](/docs/api/yii/rbac/item/index.md) | The updated item |

**Returns**

`bool`: Whether the auth item is successfully updated

**Throws**

- [`Exception`](https://www.php.net/manual/en/class.exception.php): if data validation or saving fails (such as the name of the role or permission is not unique)

### updateRule() <span id="method-updateRule"></span>

```php
abstract protected function updateRule(string $name, yii\rbac\Rule $rule): bool
```

Updates a rule to the RBAC system.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | The name of the rule being updated |
| `$rule` | [`Rule`](/docs/api/yii/rbac/rule/index.md) | The updated rule |

**Returns**

`bool`: Whether the rule is successfully updated

**Throws**

- [`Exception`](https://www.php.net/manual/en/class.exception.php): if data validation or saving fails (such as the name of the rule is not unique)