public function TokenProcessor::tokenizeLdapEntry in Lightweight Directory Access Protocol (LDAP) 8.3
Same name and namespace in other branches
- 8.4 ldap_servers/src/Processor/TokenProcessor.php \Drupal\ldap_servers\Processor\TokenProcessor::tokenizeLdapEntry()
Turn an LDAP entry into a token array suitable for the t() function.
Parameters
array $ldap_entry: The LDAP entry.
array $token_keys: Either an array of key names such as ['cn', 'dn'] or an empty array for all items.
string $pre: Prefix token prefix such as !,%,[.
string $post: Suffix token suffix such as ].
Return value
array Token array suitable for t() functions of with lowercase keys as exemplified below. The LDAP entry should be in form of single entry returned from ldap_search() function. For example: 'dn' => 'cn=jdoe,ou=campus accounts,dc=ad,dc=myuniversity,dc=edu', 'mail' => array( 0 => 'jdoe@myuniversity.edu', 'count' => 1), 'sAMAccountName' => array( 0 => 'jdoe', 'count' => 1),
Should return tokens such as: From dn attribute: [cn] = jdoe [cn:0] = jdoe [cn:last] => jdoe [cn:reverse:0] = jdoe [ou] = campus accounts [ou:0] = campus accounts [ou:last] = toledo campus [ou:reverse:0] = toledo campus [ou:reverse:1] = campus accounts [dc] = ad [dc:0] = ad [dc:1] = myuniversity [dc:2] = edu [dc:last] = edu [dc:reverse:0] = edu [dc:reverse:1] = myuniversity [dc:reverse:2] = ad From other attributes: [mail] = jdoe@myuniversity.edu [mail:0] = jdoe@myuniversity.edu [mail:last] = jdoe@myuniversity.edu [samaccountname] = jdoe [samaccountname:0] = jdoe [samaccountname:last] = jdoe [guid:0;base64_encode] = apply base64_encode() function to value [guid:0;bin2hex] = apply bin2hex() function to value [guid:0;msguid] = apply convertMsguidToString() function to value
1 call to TokenProcessor::tokenizeLdapEntry()
- TokenProcessor::tokenReplace in ldap_servers/
src/ Processor/ TokenProcessor.php - Replace a token.
File
- ldap_servers/
src/ Processor/ TokenProcessor.php, line 146
Class
- TokenProcessor
- Helper to manage LDAP tokens and process their content.
Namespace
Drupal\ldap_servers\ProcessorCode
public function tokenizeLdapEntry(array $ldap_entry, array $token_keys, $pre = self::PREFIX, $post = self::SUFFIX) {
if (!is_array($ldap_entry)) {
$this->detailLog
->log('Skipped tokenization of LDAP entry because no LDAP entry provided when called from %calling_function.', [
'%calling_function' => function_exists('debug_backtrace') ? debug_backtrace()[1]['function'] : 'undefined',
]);
// Empty array.
return [];
}
list($ldap_entry, $tokens) = $this
->compileLdapTokenEntries($ldap_entry, $token_keys, $pre, $post);
// Include the dn. It will not be handled correctly by previous loops.
$tokens[$pre . 'dn' . $post] = $ldap_entry['dn'];
return $tokens;
}