TODO: need test
возвращает всех пользователей заданной роли
@param string $role
@return array
483506
public static function findByRole(string $role): array
    {
        return static::find()->where(['id' => \Yii::$app->authManager->getUserIdsByRole($role)])->all();
    }
354789
public function deleteRole($role)
    {
        $params = [
            'role' => $role,
        ];

        $body = $this->request(self::URI_AUTH_ROLE_DELETE, $params);

        return $body;
    }
504812
public function translateToRoleNames($roles)
    {
        if (!is_array($roles)) {
            if ($roles) {
                $roles = explode(",", $roles);
            } else {
                $roles = array();
            }
        }
        foreach ($roles as $key => $role) {
            if (isset($this->_roleTranslations[$role])) {
                $roles[$key] = $this->_roleTranslations[$role];
            }
        }

        return $roles;
    }
1196151
public function syncRoles($roles)
    {
        $sync = [];
        $this->mapArray($roles, function ($role) use (&$sync) {

            $sync[] = $this->parseRoleId($role);

            return $sync;
        });

        return $this->roles()->sync($sync);
    }
22051
protected function getRole($role)
	{
		if (!isset($this->user))
			return false;

		if (isset($this->user->role))
			return $this->user->role->hasPermission($role);

		return false;
	}
1281147
public function addRole($role)
    {
        $role = strtoupper($role);
        if (static::ROLE_DEFAULT === $role) {
            return $this;
        }

        if (!$this->hasRole($role)) {
            $this->roles[] = $role;
        }

        return $this;
    }
1022892
public function hasRole(Role $role)
    {
        $this->initializeRoles();
        return array_key_exists($role->getIdentifier(), $this->roles);
    }
641367
public function hasRole($role)
    {
        if (is_string($role)) {
            return $this->roles->contains('name', $role);
        }

        if (is_array($role)) {
            foreach ($role as $r) {
                if ($this->hasRole($r)) {
                    return true;
                }
            }

            return false;
        }

        return !!$role->intersect($this->roles)->count();
    }
231319
public function hasRole($role = ''){

        $session = $this->getSession();
        $cookie = $this->getCookie();


        if ($cookie->has(self::USER_SESSION)) {
            $login = $cookie->get(self::USER_SESSION);
        }elseif (false !== $session->has(self::USER_SESSION)) {
            $login = $session->get(self::USER_SESSION);
        }else{
            return false;
        }

        $roleLogin = $login['role'];

        if (is_string($role)) {
            return $roleLogin === $role;
        }elseif(is_array($role)){
            return array_search($roleLogin, $role);
        }

        return false;
    }
1002302
public function getRoleKeys($roles)
    {
        $roles = Helpers::groupModelsAndIdentifiersByType($roles);

        $roles['strings'] = $this->getKeysByName($roles['strings']);

        $roles['models'] = Arr::pluck($roles['models'], $this->getKeyName());

        return Arr::collapse($roles);
    }
301675
public function whereHasRoleIn(array $roles)
    {
        $managerRoles = array();
        $otherRoles = array();

        foreach ($roles as $role) {
            $roleName = $role instanceof RoleInterface ? $role->getRole() : $role;

            if (preg_match('/^ROLE_WS_MANAGER_/', $roleName)) {
                $managerRoles[] = $roleName;
            } else {
                $otherRoles[] = $roleName;
            }
        }

        $eol = PHP_EOL;

        if (count($otherRoles) > 0 && count($managerRoles) === 0) {
            $this->leftJoinRights = true;
            $clause = "{$eol}({$eol}";
            $clause .= "rightRole.name IN (:roles){$eol}";
            $this->parameters[":roles"] = $otherRoles;
            $clause .= "AND{$eol}BIT_AND(rights.mask, 1) = 1{$eol})";
            $this->addWhereClause($clause);
        } elseif (count($otherRoles) === 0 && count($managerRoles) > 0) {
            $this->leftJoinRoles = true;
            $clause = "{$eol}({$eol}";
            $clause .= "role.name IN (:roles){$eol}";
            $this->parameters[":roles"] = $managerRoles;
            $this->addWhereClause($clause . ')');
        } elseif (count($otherRoles) > 0 && count($managerRoles) > 0) {
            $this->leftJoinRoles = true;
            $this->leftJoinRights = true;
            $clause = "{$eol}({$eol}({$eol}";
            $clause .= "rightRole.name IN (:otherroles){$eol}";
            $this->parameters[":otherroles"] = $otherRoles;
            $clause .= "AND{$eol}BIT_AND(rights.mask, 1) = 1{$eol}){$eol}";
            $clause .= "OR{$eol}";
            $clause .= "role.name IN (:managerroles){$eol}";
            $this->parameters[":managerroles"] = $managerRoles;
            $this->addWhereClause($clause . ")");
        }

        return $this;
    }
865808
public function translateToRoleIds($roles)
    {
        if (!is_array($roles)) {
            if ($roles) {
                $roles = explode(",", $roles);
            } else {
                $roles = array();
            }
        }

        $lookup = array_flip($this->_roleTranslations);

        foreach ($roles as $key => $role) {
            if (isset($lookup[$role])) {
                $roles[$key] = $lookup[$role];
            }
        }

        return $roles;
    }
1017031
private function deleteRole($roles)
    {
        $result = [];
        try {
            foreach ($roles as $value) {
                $role = $this->entityTypeManager->getStorage('user_role')->load($value);
                $this->entityTypeManager->getStorage('user_role')->delete([$role]);

                $result['success'][] = [
                    'role-id' => $value,
                    'role-name' => $value
                ];
            }
        } catch (\Exception $e) {
            $result['error'] = [
                'error' => 'Error: ' . get_class($e) . ', code: ' . $e->getCode() . ', message: ' . $e->getMessage()
            ];
        }

        return $result;
    }
584441
protected function findRole($role)
    {
        // Try to see if we have a role registered for the given
        // key so we can determine the role's inheritances.
        if (array_key_exists($role, $this->roles)) {
            return $this->roles[$role];
        }

        // If we couldn't find a registered role for the
        // given key, just return a new role object.
        return new SimpleRole($role);
    }
1120871
public function getRelativeRoleName($role)
    {
        $roles = $this->collectRelativeRoles();
        if (isset($roles[$role])) {
            return $roles[$role];
        }
    }
293801
public function getByName(string $role): ?IRole
    {
        if (null === $this->roles) {
            $this->getAll();
        }

        if (!isset($this->names[$role])) {
            return null;
        }

        return $this->roles[$this->names[$role]];
    }
1364359
public function destroy(Role $role)
    {
        $role->delete();

        return intend([
            'url' => route('managerarea.roles.index'),
            'with' => ['warning' => trans('cortex/foundation::messages.resource_deleted', ['resource' => trans('cortex/auth::common.role'), 'identifier' => $role->title])],
        ]);
    }