You are here

public static function LdapTransformationTraits::splitDnWithValues in Lightweight Directory Access Protocol (LDAP) 8.4

Wrapper for ldap_explode_dn().

Try to avoid working with DN directly and instead use Entry objects.

Parameters

string $dn: DN to explode.

Return value

array|false Exploded DN.

1 call to LdapTransformationTraits::splitDnWithValues()
LdapGroupManager::getFirstRdnValueFromDn in ldap_servers/src/LdapGroupManager.php
Return the first RDN Value from DN.

File

ldap_servers/src/LdapTransformationTraits.php, line 194

Class

LdapTransformationTraits
Helper functions to work around hard dependencies on the LDAP extension.

Namespace

Drupal\ldap_servers

Code

public static function splitDnWithValues(string $dn) {
  if (function_exists('ldap_explode_dn')) {
    return ldap_explode_dn($dn, 1);
  }
  $rdn = explode(',', $dn);
  $rdn = array_map(static function ($attribute) {
    $attribute = trim($attribute);

    // This is a workaround for OpenLDAP escaping Unicode values.

    /** @var string[] $elements */
    $elements = explode('=', $attribute);
    return str_replace('%', '\\', urlencode($elements[1]));
  }, $rdn);
  return [
    'count' => count($rdn),
  ] + $rdn;
}