/**
  * Modify an LDAP entry.
  *
  * @param string $dn
  *   The distinguished name of an LDAP entry.
  * @param array $attributes
  *   An array of attributes to modify
  * @param 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 boolean
  *   TRUE on success.
  *
  * @throw SimpleLdapException
  */
 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;
 }