1
0
mirror of https://github.com/danog/dns.git synced 2024-11-30 04:29:06 +01:00

Add additional fallback

This commit is contained in:
Daniil Gentili 2019-12-27 14:44:49 +01:00
parent ecbeca2ae0
commit eb0b0a26b5
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7

View File

@ -106,9 +106,23 @@ class BlockingFallbackResolver implements Resolver
$encoder = $this->encoderFactory->create();
$question = $encoder->encode($request);
$result = \dns_get_record(...$question);
$result = @\dns_get_record(...$question);
if ($result === false) {
return new Failure(new DnsException("Query for '{$name}' failed, because loading the system's DNS configuration failed and blocking fallback via dns_get_record() failed, too."));
if ($type !== Record::A) {
return new Failure(new DnsException("Query for '{$name}' failed, because loading the system's DNS configuration failed and querying records other than A records isn't supported in blocking fallback mode."));
}
$result = \gethostbynamel($name);
if ($result === false) {
return new Failure(new DnsException("Query for '{$name}' failed, because loading the system's DNS configuration failed and blocking fallback via gethostbynamel() failed, too."));
}
if ($result === []) {
return new Failure(new NoRecordException("No records returned for '{$name}' using blocking fallback mode."));
}
$records = [];
foreach ($result as $record) {
$records[] = new Record($record, Record::A, null);
}
return new Success($records);
}
$decoder = $this->decoderFactory->create();