You are here

protected function SimpleLdapServerSchema::tokenize in Simple LDAP 8

Tokenizes the given value into an array of tokens.

@link http://pear.php.net/package/Net_LDAP2/

@license http://www.gnu.org/licenses/lgpl-3.0.txt LGPLv3

Parameters

string $value:

Return value

array

1 call to SimpleLdapServerSchema::tokenize()
SimpleLdapServerSchema::parseSchemaValue in src/SimpleLdapServerSchema.php
Parse a schema value into a usable array.

File

src/SimpleLdapServerSchema.php, line 276
Contains \Drupal\simple_ldap\SimpleLdapServerSchema

Class

SimpleLdapServerSchema

Namespace

Drupal\simple_ldap

Code

protected function tokenize($value) {
  $tokens = array();
  $matches = array();

  // This one is taken from perl-lap, modified for php.
  $pattern = "/\\s* (?:([()]) | ([^'\\s()]+) | '((?:[^']+|'[^\\s)])*)') \\s*/x";

  // This one matches one big pattern wherein only one of the three subpatterns
  // matched. We are interested in the subpatterns that matched. If it matched
  // its value will be non-empty and so it is a token. Tokens may be round
  // brackets, a string, or a string enclosed by "'".
  preg_match_all($pattern, $value, $matches);

  // Loop through all tokens (full pattern match).
  for ($i = 0; $i < count($matches[0]); $i++) {

    // Loop through each sub-pattern.
    for ($j = 1; $j < 4; $j++) {

      // Pattern match in this sub-pattern.
      $token = trim($matches[$j][$i]);
      if (!empty($token)) {
        $tokens[$i] = $token;
      }
    }
  }
  return $tokens;
}