attributes = $attributes; $keys = array('supportedControl', 'supportedExtension', 'supportedFeatures', 'supportedCapabilities'); foreach ($keys as $key) { if (isset($attributes->$key)) { if (is_array($attributes->$key)) { foreach ($attributes->$key as $oid) { $this->oids[$oid] = true; } } else { $this->oids[$attributes->$key] = true; } } } } /** * Return if the capability object contains support for StartTLS * * @return bool Whether StartTLS is supported */ public function hasStartTls() { return isset($this->oids[self::LDAP_SERVER_START_TLS_OID]); } /** * Return if the capability object contains support for StartTLS * * @return bool Whether StartTLS is supported */ public function hasPagedResult() { return isset($this->oids[self::LDAP_PAGED_RESULT_OID_STRING]); } /** * Whether the ldap server is an ActiveDirectory server * * @return boolean */ public function hasAdOid() { return isset($this->oids[self::LDAP_CAP_ACTIVE_DIRECTORY_OID]); } /** * Return if the capability objects contains support for LdapV3, defaults to true if discovery failed * * @return bool */ public function hasLdapV3() { if (! isset($this->attributes) || ! isset($this->attributes->supportedLDAPVersion)) { // Default to true, if unknown return true; } return (is_string($this->attributes->supportedLDAPVersion) && (int) $this->attributes->supportedLDAPVersion === 3) || (is_array($this->attributes->supportedLDAPVersion) && in_array(3, $this->attributes->supportedLDAPVersion)); } /** * Whether the capability with the given OID is supported * * @param $oid string The OID of the capability * * @return bool */ public function hasOid($oid) { return isset($this->oids[$oid]); } /** * Get the default naming context * * @return string|null the default naming context, or null when no contexts are available */ public function getDefaultNamingContext() { // defaultNamingContext entry has higher priority if (isset($this->attributes->defaultNamingContext)) { return $this->attributes->defaultNamingContext; } // if its missing use namingContext $namingContexts = $this->namingContexts(); return empty($namingContexts) ? null : $namingContexts[0]; } /** * Fetch the namingContexts * * @return array the available naming contexts */ public function namingContexts() { if (!isset($this->attributes->namingContexts)) { return array(); } if (!is_array($this->attributes->namingContexts)) { return array($this->attributes->namingContexts); } return$this->attributes->namingContexts; } }