Creates an associative array with user role slugs and their translated names.

@internal
@since 1.8.5
@param array $roles user roles.
@return array|null
977645
protected function get_roles( $roles ) {
		if ( empty($roles) ) {
			// @codeCoverageIgnoreStart
			return null;
			// @codeCoverageIgnoreEnd
		}

		$wp_roles = wp_roles();
		$names    = $wp_roles->get_names();

		$values = array();

		foreach ( $roles as $role ) {
			$name = $role;
			if ( isset($names[ $role ]) ) {
				$name = translate_user_role($names[ $role ]);
			}
			$values[ $role ] = $name;
		}

		return $values;
	}
767992
public function getRoles(string $role): array
    {
        if(!\in_array($role, $this->roles))
            throw new UndefinedRoleException("This role '{$role}' is not registered into RoleHierarchy");
        
        return isset($this->map[$role]) ? \array_merge([], [$role], $this->map[$role]) : [$role];
    }
566331
public function setWordpressRoles(array $roles, $prefix = 'ROLE_WP_')
    {
        foreach ($roles as $key => $role) {
            $roles[$key] = $prefix.strtoupper($role);
        }

        $this->setRoles($roles);

        return $this;
    }
864611
public function getRoleNames($roles)
    {
        $roles = Helpers::groupModelsAndIdentifiersByType($roles);

        $roles['integers'] = $this->getNamesByKey($roles['integers']);

        $roles['models'] = Arr::pluck($roles['models'], 'name');

        return Arr::collapse($roles);
    }
1267809
protected function addRoles($roles)
    {
        foreach ($roles as $name => $parent) {
            if (!$this->hasRole($name)) {
                if (empty($parent) && !is_array($parent)) {
                    $parent = [];
                }
                $this->addRole(new GenericRole($name), $parent);
            }
        }

        return $this;
    }
499625
public function hasAnyRole(...$roles) {
		foreach ($roles as $role) {
			if ($this->hasRole($role)) {
				return true;
			}
		}

		return false;
	}
1254277
public function setRoles(array $roles)
    {
        $this->roleIdentifiers = [];
        $this->roles = [];
        foreach ($roles as $role) {
            if (!$role instanceof Role) {
                throw new \InvalidArgumentException(sprintf('setRoles() only accepts an array of %s instances, given: "%s"', Role::class, gettype($role)), 1397125997);
            }
            $this->addRole($role);
        }
    }
940603
private function resolveRoleHierarchy(array $roles, array $alreadySolvedRoles = []): array
    {
        foreach ($roles as $role) {
            if (isset($this->roleHierarchy[$role])) {
                if (in_array($role, $alreadySolvedRoles, true)) {
                    continue;
                }

                $alreadySolvedRoles[] = $role;
                $resolveRoles = $this->resolveRoleHierarchy($this->roleHierarchy[$role], $alreadySolvedRoles);
                $roles = array_merge($roles, $resolveRoles);
            }
        }

        return $roles;
    }
870946
public function assignTasksRoles(array $roles)
    {
        foreach ($roles as $roles => $tasks) {
            $tasks = (array) $tasks;
            $roles = (array) $roles;

            foreach ($tasks as $task) {
                $this->builder->buildTask($task)->addRoles($roles);
            }
        }
    }
1105980
public function getUsersWithRole(Role $role): array
    {
        $query = $this->getRepository()->createQueryBuilder('u')
            ->select('u')
            ->where(':role MEMBER OF u.roles')
            ->setParameter('role', $role)
            ->getQuery();

        return $query->getResult() ?? [];
    }
1260722
protected function flattenRoles(array $roles)
    {
        $roleNames = [];
        $iterator  = $this->traversalStrategy->getRolesIterator($roles);

        foreach ($iterator as $role) {
            $roleNames[] = $role->getName();
        }

        return array_unique($roleNames);
    }
303776
public function roleLoadPermissions($roles)
    {
        if (!$roles) {
            return false;
        }
        $multi = is_array($roles);
        if (!$multi) {
            $roles = [$roles];
        }
        $permissions_ids = [];

        foreach ($roles as $role) {
            if (!is_array($role->_permission_ids)) {
                $role->_permission_ids = explode(',', $role->_permission_ids);
            }
            $permissions_ids = array_merge($permissions_ids, $role->_permission_ids);
        }
        $perms = $this->permissionFetchById($permissions_ids);
        foreach ($perms as $perm) {
            foreach ($roles as $role) {
                if (in_array($perm->permission_id, $role->_permission_ids)) {
                    $role->addPermission($perm);
                    continue;
                }
            }
        }
        return true;
    }
620426
protected function isAll(array $roles)
    {
        foreach ($roles as $role) {
            if (!$this->hasRole($role)) {
                return false;
            }
        }

        return true;
    }
563357
public function getAllIncludedRoles (array $roles)
    {
        $allIncludedRoles = [];
        foreach ($this->normalizeRoleList($roles) as $role)
        {
            $includedRoleCollection = [];
            $this->findIncludedRoles($role, $includedRoleCollection);
            $allIncludedRoles = array_replace($allIncludedRoles, $includedRoleCollection);

            $includedActionCollection = [];
            $this->findIncludedActions($role, $includedActionCollection);
            $allIncludedRoles = array_replace($allIncludedRoles, $includedActionCollection);
        }

        return $allIncludedRoles;
    }
150970
public function setRoles(array $roles) {
		
		$this->roles = [];
		
		foreach($roles as $role) {

			if(!$role instanceof Role) {
				throw new \InvalidArgumentException('Role is not a role instance.');
			}
			if(array_key_exists($role->getRoleName(), $this->roles)) {
				throw new \InvalidArgumentException(sprintf("Role '%s' defined twice.", $role->getRoleName()));
			}

			$this->roles[$role->getRoleName()] = $role;

		}

		return $this;
	}
781384
protected function convertRoles($roles)
    {
        if ($roles instanceof Traversable) {
            $roles = iterator_to_array($roles);
        }

        $collectedRoles = [];
        $toCollect      = [];

        foreach ((array) $roles as $role) {
            // If it's already a RoleInterface, nothing to do as a RoleInterface contains everything already
            if ($role instanceof RoleInterface) {
                $collectedRoles[] = $role;
                continue;
            }

            // Otherwise, it's a string and hence we need to collect it
            $toCollect[] = (string) $role;
        }

        // Nothing to collect, we don't even need to hit the (potentially) costly role provider
        if (empty($toCollect)) {
            return $collectedRoles;
        }

        return array_merge($collectedRoles, $this->roleProvider->getRoles($toCollect));
    }
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;
    }