protected function LdapTransformationTraits::ldapEscapeDn in Lightweight Directory Access Protocol (LDAP) 8.4
Wrapper for ldap_escape().
Helpful for unit testing without the PHP LDAP module.
Parameters
string $value: String to escape.
Return value
string Escaped string.
2 calls to LdapTransformationTraits::ldapEscapeDn()
- LdapGroupManager::groupMembershipsFromEntryRecursive in ldap_servers/
src/ LdapGroupManager.php - Recurse through all groups, adding parent groups to $all_group_dns array.
- LdapGroupManager::groupUserMembershipsFromUserAttr in ldap_servers/
src/ LdapGroupManager.php - Get list of groups that a user is a member of using the memberOf attribute.
File
- ldap_servers/
src/ LdapTransformationTraits.php, line 23
Class
- LdapTransformationTraits
- Helper functions to work around hard dependencies on the LDAP extension.
Namespace
Drupal\ldap_serversCode
protected function ldapEscapeDn($value) : string {
if (\function_exists('ldap_escape')) {
$value = ldap_escape($value, '', LDAP_ESCAPE_DN);
}
else {
$value = self::php56PolyfillLdapEscape($value, '', 2);
}
// Copied from Symfonfy's Adapter.php for ease of use.
// Per RFC 4514, leading/trailing spaces should be encoded in DNs,
// as well as carriage returns.
if (!empty($value) && strpos($value, ' ') === 0) {
$value = '\\20' . substr($value, 1);
}
if (!empty($value) && $value[\strlen($value) - 1] === ' ') {
$value = substr($value, 0, -1) . '\\20';
}
return str_replace("\r", '\\0d', $value);
}