You are here

public function SimpleLdapSchema::exists in Simple LDAP 7.2

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

Returns whether the given item exists.

@throw SimpleLdapException

Parameters

string $attribute: Name of the schema attribute type to check.

string $name: Name or OID of a single entry to check. If NULL, then this function will return whether or not the given attribute type is empty.

Return value

boolean TRUE if the item exists, FALSE otherwise.

1 call to SimpleLdapSchema::exists()
SimpleLdapSchema::get in ./SimpleLdapSchema.class.php
Fetches entries of the given type.

File

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

Class

SimpleLdapSchema
Simple LDAP Schema class.

Code

public function exists($attribute, $name = NULL) {

  // Make sure the schema for the requested type is loaded.
  $this
    ->load($attribute);

  // Check to see if the requested schema entry exists.
  $attribute = drupal_strtolower($attribute);
  if (isset($this->schema[$attribute])) {
    if ($name === NULL) {
      return count($this->schema[$attribute]) > 0;
    }
    else {
      if (isset($this->schema[$attribute][drupal_strtolower($name)])) {

        // An attribute of the given name exists.
        return TRUE;
      }
      else {

        // Search for an alias or OID.
        foreach ($this->schema[$attribute] as $attr) {
          foreach ($attr['aliases'] as $alias) {
            if (drupal_strtolower($alias) == drupal_strtolower($name)) {
              return TRUE;
            }
          }
          if ($attr['oid'] == $name) {
            return TRUE;
          }
        }
      }
    }
  }
  return FALSE;
}