Horde_Ldap::setOption PHP Метод

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

Sets an LDAP option.
public setOption ( string $option, mixed $value )
$option string Option to set.
$value mixed Value to set option to.
    public function setOption($option, $value)
    {
        if (!$this->_link) {
            throw new Horde_Ldap_Exception('Could not set LDAP option: No LDAP connection');
        }
        if (!defined($option)) {
            throw new Horde_Ldap_Exception('Unkown option requested');
        }
        if (@ldap_set_option($this->_link, constant($option), $value)) {
            return;
        }
        $err = @ldap_errno($this->_link);
        if ($err) {
            throw new Horde_Ldap_Exception(ldap_err2str($err), $err);
        }
        throw new Horde_Ldap_Exception('Unknown error');
    }

Usage Example

Пример #1
0
 /**
  * Constructor.
  *
  * Fetches a RootDSE object from an LDAP connection.
  *
  * @param Horde_Ldap $ldap  Directory from which the RootDSE should be
  *                          fetched.
  * @param array      $attrs Array of attributes to search for.
  *
  * @throws Horde_Ldap_Exception
  */
 public function __construct(Horde_Ldap $ldap, $attrs = null)
 {
     if (is_array($attrs) && count($attrs)) {
         $attributes = $attrs;
     } else {
         $attributes = array('vendorName', 'vendorVersion', 'namingContexts', 'altServer', 'supportedExtension', 'supportedControl', 'supportedSASLMechanisms', 'supportedLDAPVersion', 'subschemaSubentry');
     }
     $referral = $ldap->getOption('LDAP_OPT_REFERRALS');
     $ldap->setOption('LDAP_OPT_REFERRALS', false);
     try {
         $result = $ldap->search('', '(objectClass=*)', array('attributes' => $attributes, 'scope' => 'base'));
     } catch (Horde_Ldap_Exception $e) {
         $ldap->setOption('LDAP_OPT_REFERRALS', $referral);
         throw $e;
     }
     $ldap->setOption('LDAP_OPT_REFERRALS', $referral);
     $entry = $result->shiftEntry();
     if (!$entry) {
         throw new Horde_Ldap_Exception('Could not fetch RootDSE entry');
     }
     $this->_entry = $entry;
 }