Horde_Ldap::getOption PHP Метод

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

Returns an LDAP option value.
public getOption ( string $option ) : Horde_Ldap_Error | string
$option string Option to get.
Результат Horde_Ldap_Error | string Horde_Ldap_Error or option value
    public function getOption($option)
    {
        if (!$this->_link) {
            throw new Horde_Ldap_Exception('No LDAP connection');
        }
        if (!defined($option)) {
            throw new Horde_Ldap_Exception('Unkown option requested');
        }
        if (@ldap_get_option($this->_link, constant($option), $value)) {
            return $value;
        }
        $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;
 }