# ManagerInterface

> For more details and usage information on ManagerInterface, see the [guide article on security authorization](https://yii2-framework.github.io/docs/guide/security-authorization/).

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

| interface | `yii\rbac\ManagerInterface` |
| --- | --- |
| Extends | [`CheckAccessInterface`](/docs/api/yii/rbac/checkaccessinterface/index.md) |
| Since | 2.0 |
| Source | [`framework/rbac/ManagerInterface.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/rbac/ManagerInterface.php#L17) |

Implemented by 1 type:

- [`BaseManager`](/docs/api/yii/rbac/basemanager/index.md)

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

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`add()`](#method-add) abstract | Adds a role, permission or rule to the RBAC system. | `ManagerInterface` |
| [`addChild()`](#method-addChild) abstract | Adds an item as a child of another item. | `ManagerInterface` |
| [`assign()`](#method-assign) abstract | Assigns a role to a user. | `ManagerInterface` |
| [`canAddChild()`](#method-canAddChild) abstract | Checks the possibility of adding a child to parent. | `ManagerInterface` |
| <span id="method-checkAccess"></span>[`checkAccess()`](/docs/api/yii/rbac/checkaccessinterface/index.md#method-checkAccess) abstract | Checks if the user has the specified permission. | [`CheckAccessInterface`](/docs/api/yii/rbac/checkaccessinterface/index.md) |
| [`createPermission()`](#method-createPermission) abstract | Creates a new Permission object. | `ManagerInterface` |
| [`createRole()`](#method-createRole) abstract | Creates a new Role object. | `ManagerInterface` |
| [`getAssignment()`](#method-getAssignment) abstract | Returns the assignment information regarding a role and a user. | `ManagerInterface` |
| [`getAssignments()`](#method-getAssignments) abstract | Returns all role assignment information for the specified user. | `ManagerInterface` |
| [`getChildren()`](#method-getChildren) abstract | Returns the child permissions and/or roles. | `ManagerInterface` |
| [`getChildRoles()`](#method-getChildRoles) abstract | Returns child roles of the role specified. Depth isn't limited. | `ManagerInterface` |
| [`getPermission()`](#method-getPermission) abstract | Returns the named permission. | `ManagerInterface` |
| [`getPermissions()`](#method-getPermissions) abstract | Returns all permissions in the system. | `ManagerInterface` |
| [`getPermissionsByRole()`](#method-getPermissionsByRole) abstract | Returns all permissions that the specified role represents. | `ManagerInterface` |
| [`getPermissionsByUser()`](#method-getPermissionsByUser) abstract | Returns all permissions that the user has. | `ManagerInterface` |
| [`getRole()`](#method-getRole) abstract | Returns the named role. | `ManagerInterface` |
| [`getRoles()`](#method-getRoles) abstract | Returns all roles in the system. | `ManagerInterface` |
| [`getRolesByUser()`](#method-getRolesByUser) abstract | Returns the roles that are assigned to the user via [`assign()`](/docs/api/yii/rbac/managerinterface/index.md#method-assign). | `ManagerInterface` |
| [`getRule()`](#method-getRule) abstract | Returns the rule of the specified name. | `ManagerInterface` |
| [`getRules()`](#method-getRules) abstract | Returns all rules available in the system. | `ManagerInterface` |
| [`getUserIdsByRole()`](#method-getUserIdsByRole) abstract | Returns all user IDs assigned to the role specified. | `ManagerInterface` |
| [`hasChild()`](#method-hasChild) abstract | Returns a value indicating whether the child already exists for the parent. | `ManagerInterface` |
| [`remove()`](#method-remove) abstract | Removes a role, permission or rule from the RBAC system. | `ManagerInterface` |
| [`removeAll()`](#method-removeAll) abstract | Removes all authorization data, including roles, permissions, rules, and assignments. | `ManagerInterface` |
| [`removeAllAssignments()`](#method-removeAllAssignments) abstract | Removes all role assignments. | `ManagerInterface` |
| [`removeAllPermissions()`](#method-removeAllPermissions) abstract | Removes all permissions. | `ManagerInterface` |
| [`removeAllRoles()`](#method-removeAllRoles) abstract | Removes all roles. | `ManagerInterface` |
| [`removeAllRules()`](#method-removeAllRules) abstract | Removes all rules. | `ManagerInterface` |
| [`removeChild()`](#method-removeChild) abstract | Removes a child from its parent. | `ManagerInterface` |
| [`removeChildren()`](#method-removeChildren) abstract | Removed all children form their parent. | `ManagerInterface` |
| [`revoke()`](#method-revoke) abstract | Revokes a role from a user. | `ManagerInterface` |
| [`revokeAll()`](#method-revokeAll) abstract | Revokes all roles from a user. | `ManagerInterface` |
| [`update()`](#method-update) abstract | Updates the specified role, permission or rule in the system. | `ManagerInterface` |

## Method details

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

```php
abstract public function add(yii\rbac\Role|yii\rbac\Permission|yii\rbac\Rule $object): bool
```

Adds a role, permission or rule to the RBAC system.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$object` | [`Role`](/docs/api/yii/rbac/role/index.md)`\|`[`Permission`](/docs/api/yii/rbac/permission/index.md)`\|`[`Rule`](/docs/api/yii/rbac/rule/index.md) |  |

**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)

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

```php
abstract public function addChild(yii\rbac\Item $parent, yii\rbac\Item $child): bool
```

Adds an item as a child of another item.

**Parameters**

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

**Returns**

`bool`: Whether the child successfully added

**Throws**

- [`yii\base\Exception`](/docs/api/yii/base/exception/index.md): if the parent-child relationship already exists or if a loop has been detected.

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

```php
abstract public function assign(yii\rbac\Role|yii\rbac\Permission $role, string|int $userId): yii\rbac\Assignment
```

Assigns a role to a user.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$role` | [`Role`](/docs/api/yii/rbac/role/index.md)`\|`[`Permission`](/docs/api/yii/rbac/permission/index.md) |  |
| `$userId` | `string\|int` | The user ID (see [`User::$id`](/docs/api/yii/web/user/index.md#property-id)) |

**Returns**

[`Assignment`](/docs/api/yii/rbac/assignment/index.md): The role assignment information.

**Throws**

- [`Exception`](https://www.php.net/manual/en/class.exception.php): if the role has already been assigned to the user

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

```php
abstract public function canAddChild(yii\rbac\Item $parent, yii\rbac\Item $child): bool
```

Checks the possibility of adding a child to parent.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$parent` | [`Item`](/docs/api/yii/rbac/item/index.md) | The parent item |
| `$child` | [`Item`](/docs/api/yii/rbac/item/index.md) | The child item to be added to the hierarchy |

**Returns**

`bool`: Possibility of adding

**Since**

2.0.8

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

```php
abstract public function createPermission(string $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/managerinterface/index.md#method-add) to add it to the system.

**Parameters**

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

**Returns**

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

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

```php
abstract public function createRole(string $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/managerinterface/index.md#method-add) to add it to the system.

**Parameters**

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

**Returns**

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

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

```php
abstract public function getAssignment(string $roleName, string|int $userId): yii\rbac\Assignment|null
```

Returns the assignment information regarding a role and a user.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$roleName` | `string` | The role name |
| `$userId` | `string\|int` | The user ID (see [`User::$id`](/docs/api/yii/web/user/index.md#property-id)) |

**Returns**

[`Assignment`](/docs/api/yii/rbac/assignment/index.md)`|null`: The assignment information. Null is returned if the role is not assigned to the user.

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

```php
abstract public function getAssignments(string|int $userId): yii\rbac\Assignment[]
```

Returns all role assignment information for the specified user.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$userId` | `string\|int` | The user ID (see [`User::$id`](/docs/api/yii/web/user/index.md#property-id)) |

**Returns**

[`Assignment`](/docs/api/yii/rbac/assignment/index.md)`[]`: The assignments indexed by role names. An empty array will be returned if there is no role assigned to the user.

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

```php
abstract public function getChildren(string $name): yii\rbac\Item[]
```

Returns the child permissions and/or roles.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | The parent name |

**Returns**

[`Item`](/docs/api/yii/rbac/item/index.md)`[]`: The child permissions and/or roles

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

```php
abstract public function getChildRoles(string $roleName): yii\rbac\Role[]
```

Returns child roles of the role specified. Depth isn't limited.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$roleName` | `string` | Name of the role to file child roles for |

**Returns**

[`Role`](/docs/api/yii/rbac/role/index.md)`[]`: Child roles. The array is indexed by the role names. First element is an instance of the parent Role itself.

**Throws**

- [`yii\base\InvalidArgumentException`](/docs/api/yii/base/invalidargumentexception/index.md): if Role was not found that are getting by $roleName

**Since**

2.0.10

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

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

Returns the named permission.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | 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
abstract 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.

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

```php
abstract public function getPermissionsByRole(string $roleName): yii\rbac\Permission[]
```

Returns all permissions that the specified role represents.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$roleName` | `string` | The role name |

**Returns**

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

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

```php
abstract public function getPermissionsByUser(string|int $userId): yii\rbac\Permission[]
```

Returns all permissions that the user has.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$userId` | `string\|int` | The user ID (see [`User::$id`](/docs/api/yii/web/user/index.md#property-id)) |

**Returns**

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

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

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

Returns the named role.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | 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
abstract 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.

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

```php
abstract public function getRolesByUser(string|int $userId): yii\rbac\Role[]
```

Returns the roles that are assigned to the user via [`assign()`](/docs/api/yii/rbac/managerinterface/index.md#method-assign).

Note that child roles that are not assigned directly to the user will not be returned.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$userId` | `string\|int` | The user ID (see [`User::$id`](/docs/api/yii/web/user/index.md#property-id)) |

**Returns**

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

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

```php
abstract public function getRule(string $name): yii\rbac\Rule|null
```

Returns the rule of the specified name.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | The rule name |

**Returns**

[`Rule`](/docs/api/yii/rbac/rule/index.md)`|null`: The rule object, or null if the specified name does not correspond to a rule.

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

```php
abstract public function getRules(): yii\rbac\Rule[]
```

Returns all rules available in the system.

**Returns**

[`Rule`](/docs/api/yii/rbac/rule/index.md)`[]`: The rules indexed by the rule names

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

```php
abstract public function getUserIdsByRole(string $roleName): array
```

Returns all user IDs assigned to the role specified.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$roleName` | `string` |  |

**Returns**

`array`: Array of user ID strings

**Since**

2.0.7

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

```php
abstract public function hasChild(yii\rbac\Item $parent, yii\rbac\Item $child): bool
```

Returns a value indicating whether the child already exists for the parent.

**Parameters**

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

**Returns**

`bool`: Whether `$child` is already a child of `$parent`

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

```php
abstract public function remove(yii\rbac\Role|yii\rbac\Permission|yii\rbac\Rule $object): bool
```

Removes a role, permission or rule from the RBAC system.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$object` | [`Role`](/docs/api/yii/rbac/role/index.md)`\|`[`Permission`](/docs/api/yii/rbac/permission/index.md)`\|`[`Rule`](/docs/api/yii/rbac/rule/index.md) |  |

**Returns**

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

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

```php
abstract public function removeAll(): mixed
```

Removes all authorization data, including roles, permissions, rules, and assignments.

**Returns**

`mixed`

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

```php
abstract public function removeAllAssignments(): mixed
```

Removes all role assignments.

**Returns**

`mixed`

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

```php
abstract public function removeAllPermissions(): mixed
```

Removes all permissions.

All parent child relations will be adjusted accordingly.

**Returns**

`mixed`

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

```php
abstract public function removeAllRoles(): mixed
```

Removes all roles.

All parent child relations will be adjusted accordingly.

**Returns**

`mixed`

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

```php
abstract public function removeAllRules(): mixed
```

Removes all rules.

All roles and permissions which have rules will be adjusted accordingly.

**Returns**

`mixed`

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

```php
abstract public function removeChild(yii\rbac\Item $parent, yii\rbac\Item $child): bool
```

Removes a child from its parent.

Note, the child item is not deleted. Only the parent-child relationship is removed.

**Parameters**

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

**Returns**

`bool`: Whether the removal is successful

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

```php
abstract public function removeChildren(yii\rbac\Item $parent): bool
```

Removed all children form their parent.

Note, the children items are not deleted. Only the parent-child relationships are removed.

**Parameters**

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

**Returns**

`bool`: Whether the removal is successful

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

```php
abstract public function revoke(yii\rbac\Role|yii\rbac\Permission $role, string|int $userId): bool
```

Revokes a role from a user.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$role` | [`Role`](/docs/api/yii/rbac/role/index.md)`\|`[`Permission`](/docs/api/yii/rbac/permission/index.md) |  |
| `$userId` | `string\|int` | The user ID (see [`User::$id`](/docs/api/yii/web/user/index.md#property-id)) |

**Returns**

`bool`: Whether the revoking is successful

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

```php
abstract public function revokeAll(mixed $userId): bool
```

Revokes all roles from a user.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$userId` | `mixed` | The user ID (see [`User::$id`](/docs/api/yii/web/user/index.md#property-id)) |

**Returns**

`bool`: Whether the revoking is successful

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

```php
abstract public function update(string $name, yii\rbac\Role|yii\rbac\Permission|yii\rbac\Rule $object): bool
```

Updates the specified role, permission or rule in the system.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | The old name of the role, permission or rule |
| `$object` | [`Role`](/docs/api/yii/rbac/role/index.md)`\|`[`Permission`](/docs/api/yii/rbac/permission/index.md)`\|`[`Rule`](/docs/api/yii/rbac/rule/index.md) |  |

**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)