You are here

public function LdapBaseManager::searchAllBaseDns in Lightweight Directory Access Protocol (LDAP) 8.4

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".

Return value

\Symfony\Component\Ldap\Entry[] An array of matching entries combined from all DN.

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

File

ldap_servers/src/LdapBaseManager.php, line 213

Class

LdapBaseManager
LDAP Base Manager.

Namespace

Drupal\ldap_servers

Code

public function searchAllBaseDns(string $filter, array $attributes = []) : array {
  $all_entries = [];
  if (!$this
    ->checkAvailability()) {
    return $all_entries;
  }
  $options = [
    'filter' => $attributes,
  ];
  $results = [];
  foreach ($this->server
    ->getBaseDn() as $base_dn) {
    $relative_filter = str_replace(',' . $base_dn, '', $filter);
    try {
      $ldap_response = $this->ldap
        ->query($base_dn, $relative_filter, $options)
        ->execute();
    } catch (LdapException $e) {
      $this->logger
        ->critical('LDAP search error with @message', [
        '@message' => $e
          ->getMessage(),
      ]);
      continue;
    }
    if ($ldap_response
      ->count() > 0) {
      $results[] = $ldap_response
        ->toArray();
    }
  }
  return array_merge(...$results);
}