Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
150 lars 2
 
148 lars 3
namespace Egulias\EmailValidator\Validation;
4
 
5
class DNSGetRecordWrapper
6
{
7
    /**
8
     * @param string $host
9
     * @param int $type
150 lars 10
     *
11
     * @return DNSRecords
148 lars 12
     */
150 lars 13
    public function getRecords(string $host, int $type): DNSRecords
148 lars 14
    {
15
        // A workaround to fix https://bugs.php.net/bug.php?id=73149
16
        /** @psalm-suppress InvalidArgument */
17
        set_error_handler(
150 lars 18
            static function (int $errorLevel, string $errorMessage): never {
148 lars 19
                throw new \RuntimeException("Unable to get DNS record for the host: $errorMessage");
20
            }
21
        );
22
        try {
23
            // Get all MX, A and AAAA DNS records for host
24
            return new DNSRecords(dns_get_record($host, $type));
25
        } catch (\RuntimeException $exception) {
26
            return new DNSRecords([], true);
27
        } finally {
28
            restore_error_handler();
29
        }
30
    }
31
}