You are here

protected function SimpleLdapSchema::tokenize in Simple LDAP 7.2

Same name and namespace in other branches
  1. 7 SimpleLdapSchema.class.php \SimpleLdapSchema::tokenize()

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

1 call to SimpleLdapSchema::tokenize()
SimpleLdapSchema::parse in ./SimpleLdapSchema.class.php
Parse a schema value into a usable array.

File

./SimpleLdapSchema.class.php, line 488
Class to represent an LDAP server schema.

Class

SimpleLdapSchema
Simple LDAP Schema class.

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 wherin 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;
}