protected function SimpleLdapSchema::parse in Simple LDAP 7.2
Same name and namespace in other branches
- 7 SimpleLdapSchema.class.php \SimpleLdapSchema::parse()
 
Parse a schema value into a usable array.
@link http://pear.php.net/package/Net_LDAP2/
@license http://www.gnu.org/licenses/lgpl-3.0.txt LGPLv3
1 call to SimpleLdapSchema::parse()
- SimpleLdapSchema::load in ./
SimpleLdapSchema.class.php  - Load the schema.
 
File
- ./
SimpleLdapSchema.class.php, line 394  - Class to represent an LDAP server schema.
 
Class
- SimpleLdapSchema
 - Simple LDAP Schema class.
 
Code
protected function parse($value) {
  // Tokens that have no associated value.
  $novalue = array(
    'single-value',
    'obsolete',
    'collective',
    'no-user-modification',
    'abstract',
    'structural',
    'auxiliary',
  );
  // Tokens that can have multiple values.
  $multivalue = array(
    'must',
    'may',
    'sup',
  );
  // Initialization.
  $schema_entry = array(
    'aliases' => array(),
  );
  // Get an array of tokens.
  $tokens = $this
    ->tokenize($value);
  // Remove left paren.
  if ($tokens[0] == '(') {
    array_shift($tokens);
  }
  // Remove right paren.
  if ($tokens[count($tokens) - 1] == ')') {
    array_pop($tokens);
  }
  // The first token is the OID.
  $schema_entry['oid'] = array_shift($tokens);
  // Loop through the tokens until there are none left.
  while (count($tokens) > 0) {
    $token = drupal_strtolower(array_shift($tokens));
    if (in_array($token, $novalue)) {
      // Single value token.
      $schema_entry[$token] = 1;
    }
    else {
      // This one follows a string or a list if it is multivalued.
      if (($schema_entry[$token] = array_shift($tokens)) == '(') {
        // This creates the list of values and cycles through the tokens until
        // the end of the list is reached ')'.
        $schema_entry[$token] = array();
        while ($tmp = array_shift($tokens)) {
          if ($tmp == ')') {
            break;
          }
          if ($tmp != '$') {
            array_push($schema_entry[$token], $tmp);
          }
        }
      }
      // Create an array if the value should be multivalued but was not.
      if (in_array($token, $multivalue) && !is_array($schema_entry[$token])) {
        $schema_entry[$token] = array(
          $schema_entry[$token],
        );
      }
    }
  }
  // Get the max length from syntax.
  if (key_exists('syntax', $schema_entry)) {
    if (preg_match('/{(\\d+)}/', $schema_entry['syntax'], $matches)) {
      $schema_entry['max_length'] = $matches[1];
    }
  }
  // Force a name.
  if (empty($schema_entry['name'])) {
    $schema_entry['name'] = $schema_entry['oid'];
  }
  // Make one name the default and put the others into aliases.
  if (is_array($schema_entry['name'])) {
    $aliases = $schema_entry['name'];
    $schema_entry['name'] = array_shift($aliases);
    $schema_entry['aliases'] = $aliases;
  }
  return $schema_entry;
}