/** * 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'); }
function it_should_throw_an_error_when_no_servers_are_returned_from_dns(TcpSocket $tcp, Dns $dns) { $e = new LdapConnectionException('No LDAP servers found via DNS for "example.com".'); $dns->getRecord("_ldap._tcp.example.com", DNS_SRV)->willReturn(false); $config = new DomainConfiguration('example.com'); $this->beConstructedWith($config, $tcp, $dns); $this->shouldThrow($e)->duringGetServer(); }