You are here

protected function SimpleLdapSchema::load in Simple LDAP 7

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

Load the schema.

Schema parsing can be slow, so only the attributes that are specified, and are not already cached, are loaded.

@throw SimpleLdapException

Parameters

array $attributes: A list of attributes to load. If not specified, all attributes are loaded.

2 calls to SimpleLdapSchema::load()
SimpleLdapSchema::exists in ./SimpleLdapSchema.class.php
Returns whether the given item exists.
SimpleLdapSchema::__get in ./SimpleLdapSchema.class.php
Magic __get function.

File

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

Class

SimpleLdapSchema
Simple LDAP Schema class.

Code

protected function load($attributes = NULL) {

  // If no attributes are specified, default to all attributes.
  if ($attributes === NULL) {
    $attributes = $this->attributes;
  }

  // Make sure $attributes is an array.
  if (!is_array($attributes)) {
    $attributes = array(
      $attributes,
    );
  }

  // Determine which attributes need to be loaded.
  $load = array();
  foreach ($attributes as $attribute) {
    $attribute = drupal_strtolower($attribute);
    if (!isset($this->schema[$attribute])) {
      $load[] = $attribute;
    }
  }

  // Load the attributes.
  if (!empty($load)) {
    $result = SimpleLdap::clean($this->server
      ->search($this->dn, 'objectclass=*', 'base', $load));

    // Parse the schema.
    foreach ($load as $attribute) {
      $attribute = drupal_strtolower($attribute);
      $this->schema[$attribute] = array();

      // Get the values for each attribute.
      if (isset($result[$this->dn][$attribute])) {
        foreach ($result[$this->dn][$attribute] as $value) {
          $parsed = $this
            ->parse($value);
          $this->schema[$attribute][drupal_strtolower($parsed['name'])] = $parsed;
        }
      }
    }
  }
}