private function TokenProcessor::ldapTokenizationProcessDnParts in Lightweight Directory Access Protocol (LDAP) 8.3
Tokenization of DN parts.
Parameters
array $ldap_entry: LDAP entry.
string $pre: Preamble.
string $post: Postamble.
Return value
array Tokens.
1 call to TokenProcessor::ldapTokenizationProcessDnParts()
- TokenProcessor::compileLdapTokenEntries in ldap_servers/
src/ Processor/ TokenProcessor.php - Compile LDAP token entries.
File
- ldap_servers/
src/ Processor/ TokenProcessor.php, line 388
Class
- TokenProcessor
- Helper to manage LDAP tokens and process their content.
Namespace
Drupal\ldap_servers\ProcessorCode
private function ldapTokenizationProcessDnParts(array $ldap_entry, $pre, $post) {
$tokens = [];
// 1. tokenize dn
// escapes attribute values, need to be unescaped later.
$dn_parts = Server::ldapExplodeDn($ldap_entry['dn'], 0);
unset($dn_parts['count']);
$parts_count = [];
$parts_last_value = [];
foreach ($dn_parts as $pair) {
list($attribute_name, $attribute_value) = explode('=', $pair);
$attribute_value = ConversionHelper::unescapeDnValue($attribute_value);
if (!Unicode::validateUtf8($attribute_value)) {
$this->detailLog
->log('Skipped tokenization of attribute %attr_name because the value is not valid UTF-8 string.', [
'%attr_name' => $attribute_name,
]);
continue;
}
if (!isset($parts_count[$attribute_name])) {
// First and general entry.
$tokens[$pre . mb_strtolower($attribute_name) . $post] = $attribute_value;
$parts_count[$attribute_name] = 0;
}
$tokens[$pre . mb_strtolower($attribute_name) . self::DELIMITER . (int) $parts_count[$attribute_name] . $post] = $attribute_value;
$parts_last_value[$attribute_name] = $attribute_value;
$parts_count[$attribute_name]++;
}
// Add DN parts in reverse order to reflect the hierarchy for CN, OU, DC.
foreach ($parts_count as $attribute_name => $count) {
$part = mb_strtolower($attribute_name);
for ($i = 0; $i < $count; $i++) {
$reversePosition = $count - $i - 1;
$tokens[$pre . $part . self::DELIMITER . 'reverse' . self::DELIMITER . $reversePosition . $post] = $tokens[$pre . $part . self::DELIMITER . $i . $post];
}
}
foreach ($parts_count as $attribute_name => $count) {
$tokens[$pre . mb_strtolower($attribute_name) . self::DELIMITER . 'last' . $post] = $parts_last_value[$attribute_name];
}
return $tokens;
}