You are here

protected function KeycloakRoleMatcher::getSplitGroups in Keycloak OpenID Connect 8

Return split user groups.

Keycloak user groups can be nested. This helper method flattens nested group paths to an one-level array of group path segments.

Parameters

array $groups: Array of user group paths as returned by Keycloak.

int $max_level: (Optional) Maximum level to split into the result. If a level greater than 0 is given, the splitting will ignore user groups with a higher nesting level. Level counting starts at 1. If a maximum of 0 is given, ALL levels will be included. Defaults to 0.

Return value

array Transformed user groups array.

1 call to KeycloakRoleMatcher::getSplitGroups()
KeycloakRoleMatcher::applyRoleRules in src/Service/KeycloakRoleMatcher.php
Applies user role rules to the given user account.

File

src/Service/KeycloakRoleMatcher.php, line 382

Class

KeycloakRoleMatcher
Role matcher service.

Namespace

Drupal\keycloak\Service

Code

protected function getSplitGroups(array $groups, $max_level = 0) {
  $target = [];
  foreach ($groups as $group) {
    $segments = explode('/', trim($group, '/'));
    if ($max_level > 0) {
      $segments = array_slice($segments, 0, $max_level);
    }
    $target = array_merge($target, $segments);
  }
  return array_unique($target);
}