public function setVersion($version = 0, $force = false)
{
if (!$version) {
$version = $this->_config['version'];
}
/* Check to see if the server supports this version first.
*
* TODO: Why is this so horribly slow? $this->rootDSE() is very fast,
* as well as Horde_Ldap_RootDse(). Seems like a problem at copying the
* object inside PHP?? Additionally, this is not always
* reproducable... */
if (!$force) {
try {
$rootDSE = $this->rootDSE();
$supported_versions = $rootDSE->getValue('supportedLDAPVersion');
if (is_string($supported_versions)) {
$supported_versions = array($supported_versions);
}
$check_ok = in_array($version, $supported_versions);
} catch (Horde_Ldap_Exception $e) {
/* If we don't get a root DSE, this is probably a v2 server. */
$check_ok = $version < 3;
}
}
$check_ok = true;
if ($force || $check_ok) {
return $this->setOption('LDAP_OPT_PROTOCOL_VERSION', $version);
}
throw new Horde_Ldap_Exception('LDAP Server does not support protocol version ' . $version);
}