Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Ganze Datei anzeigen | Leerzeichen ignorieren | Details | Blame | Letzte Änderung | Log anzeigen | RSS feed

Revision 148 Revision 150
Zeile 7... Zeile 7...
7
use Egulias\EmailValidator\Result\Reason\DomainAcceptsNoMail;
7
use Egulias\EmailValidator\Result\Reason\DomainAcceptsNoMail;
8
use Egulias\EmailValidator\Result\Reason\LocalOrReservedDomain;
8
use Egulias\EmailValidator\Result\Reason\LocalOrReservedDomain;
9
use Egulias\EmailValidator\Result\Reason\NoDNSRecord as ReasonNoDNSRecord;
9
use Egulias\EmailValidator\Result\Reason\NoDNSRecord as ReasonNoDNSRecord;
10
use Egulias\EmailValidator\Result\Reason\UnableToGetDNSRecord;
10
use Egulias\EmailValidator\Result\Reason\UnableToGetDNSRecord;
11
use Egulias\EmailValidator\Warning\NoDNSMXRecord;
11
use Egulias\EmailValidator\Warning\NoDNSMXRecord;
-
 
12
use Egulias\EmailValidator\Warning\Warning;
Zeile 12... Zeile 13...
12
 
13
 
13
class DNSCheckValidation implements EmailValidation
14
class DNSCheckValidation implements EmailValidation
14
{
15
{
15
    /**
16
    /**
Zeile 18... Zeile 19...
18
    protected const DNS_RECORD_TYPES_TO_CHECK = DNS_MX + DNS_A + DNS_AAAA;
19
    protected const DNS_RECORD_TYPES_TO_CHECK = DNS_MX + DNS_A + DNS_AAAA;
Zeile 19... Zeile 20...
19
 
20
 
20
    /**
21
    /**
21
     * Reserved Top Level DNS Names (https://tools.ietf.org/html/rfc2606#section-2),
22
     * Reserved Top Level DNS Names (https://tools.ietf.org/html/rfc2606#section-2),
-
 
23
     * mDNS and private DNS Namespaces (https://tools.ietf.org/html/rfc6762#appendix-G)
-
 
24
     * 
22
     * mDNS and private DNS Namespaces (https://tools.ietf.org/html/rfc6762#appendix-G)
25
     * @var string[]
23
     */
26
     */
24
    public const RESERVED_DNS_TOP_LEVEL_NAMES = [
27
    public const RESERVED_DNS_TOP_LEVEL_NAMES = [
25
        // Reserved Top Level DNS Names
28
        // Reserved Top Level DNS Names
26
        'test',
29
        'test',
Zeile 37... Zeile 40...
37
        'private',
40
        'private',
38
        'corp',
41
        'corp',
39
        'home',
42
        'home',
40
        'lan',
43
        'lan',
41
    ];
44
    ];
42
    
45
 
43
    /**
46
    /**
44
     * @var array
47
     * @var Warning[]
45
     */
48
     */
46
    private $warnings = [];
49
    private $warnings = [];
Zeile 47... Zeile 50...
47
 
50
 
48
    /**
51
    /**
Zeile 71... Zeile 74...
71
        }
74
        }
Zeile 72... Zeile 75...
72
 
75
 
73
        $this->dnsGetRecord = $dnsGetRecord;
76
        $this->dnsGetRecord = $dnsGetRecord;
Zeile 74... Zeile 77...
74
    }
77
    }
75
 
78
 
76
    public function isValid(string $email, EmailLexer $emailLexer) : bool
79
    public function isValid(string $email, EmailLexer $emailLexer): bool
77
    {
80
    {
Zeile 78... Zeile 81...
78
        // use the input to check DNS if we cannot extract something similar to a domain
81
        // use the input to check DNS if we cannot extract something similar to a domain
Zeile 96... Zeile 99...
96
        }
99
        }
Zeile 97... Zeile 100...
97
 
100
 
98
        return $this->checkDns($host);
101
        return $this->checkDns($host);
Zeile 99... Zeile 102...
99
    }
102
    }
100
 
103
 
101
    public function getError() : ?InvalidEmail
104
    public function getError(): ?InvalidEmail
102
    {
105
    {
Zeile -... Zeile 106...
-
 
106
        return $this->error;
-
 
107
    }
-
 
108
 
103
        return $this->error;
109
    /**
104
    }
110
     * @return Warning[]
105
 
111
     */
106
    public function getWarnings() : array
112
    public function getWarnings(): array
Zeile 107... Zeile 113...
107
    {
113
    {
Zeile 115... Zeile 121...
115
     */
121
     */
116
    protected function checkDns($host)
122
    protected function checkDns($host)
117
    {
123
    {
118
        $variant = INTL_IDNA_VARIANT_UTS46;
124
        $variant = INTL_IDNA_VARIANT_UTS46;
Zeile 119... Zeile 125...
119
 
125
 
-
 
126
        $host = rtrim(idn_to_ascii($host, IDNA_DEFAULT, $variant), '.');
-
 
127
 
-
 
128
        $hostParts = explode('.', $host);
-
 
129
        $host = array_pop($hostParts);
-
 
130
 
-
 
131
        while (count($hostParts) > 0) {
-
 
132
            $host = array_pop($hostParts) . '.' . $host;
-
 
133
 
-
 
134
            if ($this->validateDnsRecords($host)) {
-
 
135
                return true;
-
 
136
            }
Zeile 120... Zeile 137...
120
        $host = rtrim(idn_to_ascii($host, IDNA_DEFAULT, $variant), '.') . '.';
137
        }
121
 
138
 
Zeile 122... Zeile 139...
122
        return $this->validateDnsRecords($host);
139
        return false;
123
    }
140
    }
124
 
141
 
125
 
142
 
126
    /**
143
    /**
127
     * Validate the DNS records for given host.
144
     * Validate the DNS records for given host.
128
     *
145
     *
129
     * @param string $host A set of DNS records in the format returned by dns_get_record.
146
     * @param string $host A set of DNS records in the format returned by dns_get_record.
130
     *
147
     *
131
     * @return bool True on success.
148
     * @return bool True on success.
Zeile 132... Zeile 149...
132
     */
149
     */
133
    private function validateDnsRecords($host) : bool
150
    private function validateDnsRecords($host): bool
Zeile 165... Zeile 182...
165
     *
182
     *
166
     * @param array $dnsRecord Given DNS record.
183
     * @param array $dnsRecord Given DNS record.
167
     *
184
     *
168
     * @return bool True if valid.
185
     * @return bool True if valid.
169
     */
186
     */
170
    private function validateMxRecord($dnsRecord) : bool
187
    private function validateMxRecord($dnsRecord): bool
171
    {
188
    {
172
        if (!isset($dnsRecord['type'])) {
189
        if (!isset($dnsRecord['type'])) {
173
            $this->error = new InvalidEmail(new ReasonNoDNSRecord(), '');
190
            $this->error = new InvalidEmail(new ReasonNoDNSRecord(), '');
174
            return false;
191
            return false;
175
        }
192
        }