You are here

public function SimpleLdapServer::modify in Simple LDAP 7.2

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

Modify an LDAP entry.

@throw SimpleLdapException

Parameters

string $dn: The distinguished name of an LDAP entry.

array $attributes: An array of attributes to modify

string $type: The type of LDAP modification operation to use. Valid values are 'add', 'del' or 'delete', and 'replace'. If unspecified, an object-level modify is performed.

Return value

boolean TRUE on success.

File

./SimpleLdapServer.class.php, line 553
Class to handle LDAP server connections and related operations.

Class

SimpleLdapServer
Simple LDAP server class.

Code

public function modify($dn, $attributes, $type = NULL) {

  // Make sure changes are allowed.
  if ($this->readonly) {
    throw new SimpleLdapException('The LDAP Server is configured as read-only');
  }

  // Make sure there is a valid binding.
  $this
    ->bind();

  // Clean up the attributes array.
  $attributes = SimpleLdap::removeEmptyAttributes($attributes, FALSE);

  // Perform the LDAP modify.
  switch ($type) {
    case 'add':
      $result = SimpleLdap::ldap_mod_add($this->resource, $dn, $attributes);
      break;
    case 'del':
    case 'delete':
      $result = SimpleLdap::ldap_mod_del($this->resource, $dn, $attributes);
      break;
    case 'replace':
      $result = SimpleLdap::ldap_mod_replace($this->resource, $dn, $attributes);
      break;
    default:
      $result = SimpleLdap::ldap_modify($this->resource, $dn, $attributes);
  }
  return $result;
}