You are here

private function TokenProcessor::processSingleLdapTokenKey in Lightweight Directory Access Protocol (LDAP) 8.3

Process a single LDAP Token key.

Parameters

array $ldap_entry: LDAP entry.

string $pre: Preamble.

string $post: Postamble.

string $full_token_key: Actual data.

Return value

array Tokens.

1 call to TokenProcessor::processSingleLdapTokenKey()
TokenProcessor::compileLdapTokenEntries in ldap_servers/src/Processor/TokenProcessor.php
Compile LDAP token entries.

File

ldap_servers/src/Processor/TokenProcessor.php, line 488

Class

TokenProcessor
Helper to manage LDAP tokens and process their content.

Namespace

Drupal\ldap_servers\Processor

Code

private function processSingleLdapTokenKey(array $ldap_entry, $pre, $post, $full_token_key) {
  $tokens = [];

  // A token key is for example 'dn', 'mail:0', 'mail:last', or
  // 'guid:0;tobase64'.
  $value = NULL;

  // Trailing period to allow for empty value.
  list($token_key, $conversion) = explode(';', $full_token_key . ';');
  $parts = explode(self::DELIMITER, $token_key);
  $attribute_name = mb_strtolower($parts[0]);
  $ordinal_key = isset($parts[1]) ? $parts[1] : 0;
  $i = NULL;

  // Don't use empty() since a 0, "", etc value may be a desired value.
  if ($attribute_name == 'dn' || !isset($ldap_entry[$attribute_name])) {
    return [];
  }
  else {
    $count = $ldap_entry[$attribute_name]['count'];
    if ($ordinal_key === 'last') {
      $i = $count > 0 ? $count - 1 : 0;
      $value = $ldap_entry[$attribute_name][$i];
    }
    elseif (is_numeric($ordinal_key) || $ordinal_key == '0') {
      $value = $ldap_entry[$attribute_name][$ordinal_key];
    }
    else {

      // don't add token if case not covered.
      return [];
    }
  }
  $value = ConversionHelper::convertAttribute($value, $conversion);
  $tokens[$pre . $full_token_key . $post] = $value;

  // We are redundantly setting the lowercase value here for consistency with
  // parent function.
  if ($full_token_key != mb_strtolower($full_token_key)) {
    $tokens[$pre . mb_strtolower($full_token_key) . $post] = $value;
  }
  return $tokens;
}