Horde_Ldap::exists PHP Метод

exists() публичный Метод

Returns whether a DN exists in the directory.
public exists ( string | Horde_Ldap_Entry $dn ) : boolean
$dn string | Horde_Ldap_Entry The DN of the object to test.
Результат boolean True if the DN exists.
    public function exists($dn)
    {
        if ($dn instanceof Horde_Ldap_Entry) {
            $dn = $dn->dn();
        }
        if (!is_string($dn)) {
            throw new Horde_Ldap_Exception('Parameter $dn is not a string nor an entry object!');
        }
        /* Make dn relative to parent. */
        $options = array('casefold' => 'none');
        $base = Horde_Ldap_Util::explodeDN($dn, $options);
        $entry_rdn = '(&(' . Horde_Ldap_Util::canonicalDN(array_shift($base), array_merge($options, array('separator' => ')('))) . '))';
        $base = Horde_Ldap_Util::canonicalDN($base, $options);
        $result = @ldap_list($this->_link, $base, $entry_rdn, array('dn'), 1, 1);
        if ($result && @ldap_count_entries($this->_link, $result)) {
            return true;
        }
        if ($this->errorName(@ldap_errno($this->_link)) == 'LDAP_NO_SUCH_OBJECT') {
            return false;
        }
        if (@ldap_errno($this->_link)) {
            throw new Horde_Ldap_Exception(@ldap_error($this->_link), @ldap_errno($this->_link));
        }
        return false;
    }

Usage Example

Пример #1
0
 /**
  * Checks if a group exists.
  *
  * @param mixed $gid  A group ID.
  *
  * @return boolean  True if the group exists.
  * @throws Horde_Group_Exception
  */
 public function exists($gid)
 {
     try {
         return $this->_ldap->exists($gid);
     } catch (Horde_Ldap_Exception $e) {
         throw new Horde_Group_Exception($e);
     }
 }
All Usage Examples Of Horde_Ldap::exists