You are here

private function OrphanProcessor::binaryFilter in Lightweight Directory Access Protocol (LDAP) 8.4

Same name and namespace in other branches
  1. 8.3 ldap_user/src/Processor/OrphanProcessor.php \Drupal\ldap_user\Processor\OrphanProcessor::binaryFilter()

Create a "binary safe" string for use in LDAP filters.

Parameters

string $value: Unsfe string.

Return value

string Safe string.

1 call to OrphanProcessor::binaryFilter()
OrphanProcessor::ldapQueryEligibleUser in ldap_user/src/Processor/OrphanProcessor.php
Check eligible user against directory.

File

ldap_user/src/Processor/OrphanProcessor.php, line 190

Class

OrphanProcessor
Locates potential orphan user accounts.

Namespace

Drupal\ldap_user\Processor

Code

private function binaryFilter(string $value) : string {
  $match = '';
  if (preg_match('/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i', $value)) {

    // Reconstruct proper "memory" order from (MS?) GUID string.
    $hex_string = str_replace('-', '', $value);
    $value = substr($hex_string, 6, 2) . substr($hex_string, 4, 2) . substr($hex_string, 2, 2) . substr($hex_string, 0, 2) . substr($hex_string, 10, 2) . substr($hex_string, 8, 2) . substr($hex_string, 14, 2) . substr($hex_string, 12, 2) . substr($hex_string, 16, 4) . substr($hex_string, 20, 12);
  }
  $length = \strlen($value);
  for ($i = 0; $i < $length; $i += 2) {
    $match .= '\\' . substr($value, $i, 2);
  }
  return $match;
}