You are here

public function Server::searchAllBaseDns in Lightweight Directory Access Protocol (LDAP) 8.3

Perform an LDAP search on all base dns and aggregate into one result.

Parameters

string $filter: The search filter, such as sAMAccountName=jbarclay. Attribute values (e.g. jbarclay) should be esacaped before calling.

array $attributes: List of desired attributes. If omitted, we only return "dn".

int $scope: Scope of the search, defaults to subtree.

Return value

array|bool An array of matching entries->attributes (will have 0 elements if search returns no results), or FALSE on error on any of the base DN queries.

1 call to Server::searchAllBaseDns()
Server::groupMembersRecursive in ldap_servers/src/Entity/Server.php
Recurse through all child groups and add members.

File

ldap_servers/src/Entity/Server.php, line 672

Class

Server
Defines the Server entity.

Namespace

Drupal\ldap_servers\Entity

Code

public function searchAllBaseDns($filter, array $attributes = [], $scope = NULL) {
  if ($scope == NULL) {
    $scope = Server::SCOPE_SUBTREE;
  }
  $allEntries = [];
  foreach ($this
    ->getBaseDn() as $baseDn) {
    $relativeFilter = str_replace(',' . $baseDn, '', $filter);
    $entries = $this
      ->search($baseDn, $relativeFilter, $attributes, 0, 0, 0, NULL, $scope);

    // If error in any search, return false.
    if ($entries === FALSE) {
      return FALSE;
    }
    if (count($allEntries) == 0) {
      $allEntries = $entries;
    }
    else {
      $existingCount = $allEntries['count'];
      unset($entries['count']);
      foreach ($entries as $i => $entry) {
        $allEntries[$existingCount + $i] = $entry;
      }
      $allEntries['count'] = count($allEntries);
    }
  }
  return $allEntries;
}