Skip to content

Commit

Permalink
simplify error handling for dns_get_record()
Browse files Browse the repository at this point in the history
  • Loading branch information
aivchen authored and Andrei Ivchenkov committed Dec 27, 2024
1 parent 793eb01 commit 582d3cf
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions src/Validation/DNSGetRecordWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,7 @@ class DNSGetRecordWrapper
*/
public function getRecords(string $host, int $type): DNSRecords
{
// A workaround to fix https://bugs.php.net/bug.php?id=73149
set_error_handler(
static function (int $errorLevel, string $errorMessage): never {
throw new \RuntimeException("Unable to get DNS record for the host: $errorMessage");
}
);
try {
// Get all MX, A and AAAA DNS records for host
return new DNSRecords(dns_get_record($host, $type));
} catch (\RuntimeException $exception) {
return new DNSRecords([], true);
} finally {
restore_error_handler();
}
$result = @dns_get_record($host, $type);
return new DNSRecords($result === false ? [] : $result, $result === false);
}
}

0 comments on commit 582d3cf

Please sign in to comment.