/** * Attempt to lookup the LDAP servers from the DNS name. * * @return array The LDAP servers. * @throws LdapConnectionException */ protected function getServersFromDns() { $servers = $this->dns->getRecord(LdapUtilities::SRV_PREFIX . $this->config->getDomainName(), DNS_SRV); if ($servers === false || empty($servers)) { throw new LdapConnectionException(sprintf('No LDAP servers found via DNS for "%s".', $this->config->getDomainName())); } array_multisort(array_column($servers, 'pri'), SORT_ASC | SORT_NUMERIC, array_column($servers, 'weight'), SORT_DESC | SORT_NUMERIC, $servers); return array_column($servers, 'target'); }
/** * Given the connection resource and the other required parameters, attempt the bind and return the result. * * @param string $username * @return string */ public function getUsername($username) { $replacements = [$username, $this->config->getDomainName()]; return preg_replace($this->params, $replacements, $this->bindFormat); }