You are here

public function SimpleLdap::clean in Simple LDAP 8

Cleans up an array returned by the ldap_* functions.

Parameters

array $entry: An LDAP entry as returned by SimpleLdapServer::search()

Return value

array A scrubbed array, with all of the "extra crud" removed, with the DN of the record as the array index.

Throws

SimpleLdapException

File

src/SimpleLdap.php, line 41

Class

SimpleLdap
A wrapper for PHP's LDAP functions, with associated helper methods.

Namespace

Drupal\simple_ldap

Code

public function clean($entry) {
  if (!is_array($entry)) {
    throw new SimpleLdapException('Can only clean an array.');
  }
  $clean = array();

  // Yes, this is ugly, but so are the ldap_*() results.
  for ($i = 0; $i < $entry['count']; $i++) {
    $clean[$entry[$i]['dn']] = array();
    for ($j = 0; $j < $entry[$i]['count']; $j++) {
      $clean[$entry[$i]['dn']][$entry[$i][$j]] = array();
      for ($k = 0; $k < $entry[$i][$entry[$i][$j]]['count']; $k++) {
        $clean[$entry[$i]['dn']][$entry[$i][$j]][] = $entry[$i][$entry[$i][$j]][$k];
      }
    }
  }
  return $clean;
}