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 1... Zeile 1...
1
<?php
1
<?php
-
 
2
 
2
namespace Egulias\EmailValidator\Parser;
3
namespace Egulias\EmailValidator\Parser;
Zeile 3... Zeile 4...
3
 
4
 
4
use Egulias\EmailValidator\EmailLexer;
5
use Egulias\EmailValidator\EmailLexer;
5
use Egulias\EmailValidator\Result\Result;
6
use Egulias\EmailValidator\Result\Result;
Zeile 29... Zeile 30...
29
        EmailLexer::C_DEL,
30
        EmailLexer::C_DEL,
30
        EmailLexer::S_LF,
31
        EmailLexer::S_LF,
31
        EmailLexer::S_BACKSLASH
32
        EmailLexer::S_BACKSLASH
32
    ];
33
    ];
Zeile 33... Zeile 34...
33
 
34
 
34
    public function parse() : Result
35
    public function parse(): Result
35
    {
36
    {
Zeile 36... Zeile 37...
36
        $this->addTagWarnings();
37
        $this->addTagWarnings();
37
 
38
 
Zeile 38... Zeile 39...
38
        $IPv6TAG = false;
39
        $IPv6TAG = false;
39
        $addressLiteral = '';
40
        $addressLiteral = '';
40
 
41
 
41
        do {
42
        do {
Zeile 42... Zeile 43...
42
            if ($this->lexer->token['type'] === EmailLexer::C_NUL) {
43
            if ($this->lexer->current->isA(EmailLexer::C_NUL)) {
Zeile 43... Zeile 44...
43
                return new InvalidEmail(new ExpectingDTEXT(), $this->lexer->token['value']);
44
                return new InvalidEmail(new ExpectingDTEXT(), $this->lexer->current->value);
44
            }
45
            }
45
 
46
 
Zeile 46... Zeile 47...
46
            $this->addObsoleteWarnings();
47
            $this->addObsoleteWarnings();
47
 
48
 
48
            if ($this->lexer->isNextTokenAny(array(EmailLexer::S_OPENBRACKET, EmailLexer::S_OPENBRACKET))) {
49
            if ($this->lexer->isNextTokenAny(array(EmailLexer::S_OPENBRACKET, EmailLexer::S_OPENBRACKET))) {
49
                return new InvalidEmail(new ExpectingDTEXT(), $this->lexer->token['value']);
50
                return new InvalidEmail(new ExpectingDTEXT(), $this->lexer->current->value);
50
            }
51
            }
51
 
52
 
Zeile 52... Zeile 53...
52
            if ($this->lexer->isNextTokenAny(
53
            if ($this->lexer->isNextTokenAny(
53
                array(EmailLexer::S_HTAB, EmailLexer::S_SP, EmailLexer::CRLF)
54
                array(EmailLexer::S_HTAB, EmailLexer::S_SP, EmailLexer::CRLF)
54
            )) {
55
            )) {
Zeile 55... Zeile 56...
55
                $this->warnings[CFWSWithFWS::CODE] = new CFWSWithFWS();
56
                $this->warnings[CFWSWithFWS::CODE] = new CFWSWithFWS();
56
                $this->parseFWS();
57
                $this->parseFWS();
57
            }
58
            }
58
 
59
 
59
            if ($this->lexer->isNextToken(EmailLexer::S_CR)) {
60
            if ($this->lexer->isNextToken(EmailLexer::S_CR)) {
60
                return new InvalidEmail(new CRNoLF(), $this->lexer->token['value']);
61
                return new InvalidEmail(new CRNoLF(), $this->lexer->current->value);
Zeile 61... Zeile 62...
61
            }
62
            }
62
 
63
 
63
            if ($this->lexer->token['type'] === EmailLexer::S_BACKSLASH) {
64
            if ($this->lexer->current->isA(EmailLexer::S_BACKSLASH)) {
Zeile 64... Zeile 65...
64
                return new InvalidEmail(new UnusualElements($this->lexer->token['value']), $this->lexer->token['value']);
65
                return new InvalidEmail(new UnusualElements($this->lexer->current->value), $this->lexer->current->value);
65
            }
-
 
66
            if ($this->lexer->token['type'] === EmailLexer::S_IPV6TAG) {
66
            }
Zeile 67... Zeile 67...
67
                $IPv6TAG = true;
67
            if ($this->lexer->current->isA(EmailLexer::S_IPV6TAG)) {
68
            }
68
                $IPv6TAG = true;
Zeile 100... Zeile 100...
100
 
100
 
101
    /**
101
    /**
102
     * @param string $addressLiteral
102
     * @param string $addressLiteral
103
     * @param int $maxGroups
103
     * @param int $maxGroups
104
     */
104
     */
105
    public function checkIPV6Tag($addressLiteral, $maxGroups = 8) : void
105
    public function checkIPV6Tag($addressLiteral, $maxGroups = 8): void
106
    {
106
    {
107
        $prev = $this->lexer->getPrevious();
107
        $prev = $this->lexer->getPrevious();
108
        if ($prev['type'] === EmailLexer::S_COLON) {
108
        if ($prev->isA(EmailLexer::S_COLON)) {
109
            $this->warnings[IPV6ColonEnd::CODE] = new IPV6ColonEnd();
109
            $this->warnings[IPV6ColonEnd::CODE] = new IPV6ColonEnd();
Zeile 110... Zeile 110...
110
        }
110
        }
111
 
111
 
Zeile 142... Zeile 142...
142
            $this->warnings[IPV6MaxGroups::CODE] = new IPV6MaxGroups();
142
            $this->warnings[IPV6MaxGroups::CODE] = new IPV6MaxGroups();
143
        } elseif ($groupCount === $maxGroups) {
143
        } elseif ($groupCount === $maxGroups) {
144
            $this->warnings[IPV6Deprecated::CODE] = new IPV6Deprecated();
144
            $this->warnings[IPV6Deprecated::CODE] = new IPV6Deprecated();
145
        }
145
        }
146
    }
146
    }
147
    
147
 
148
    public function convertIPv4ToIPv6(string $addressLiteralIPv4) : string
148
    public function convertIPv4ToIPv6(string $addressLiteralIPv4): string
149
    {
149
    {
150
        $matchesIP  = [];
150
        $matchesIP  = [];
151
        $IPv4Match = preg_match(self::IPV4_REGEX, $addressLiteralIPv4, $matchesIP);
151
        $IPv4Match = preg_match(self::IPV4_REGEX, $addressLiteralIPv4, $matchesIP);
Zeile 152... Zeile 152...
152
 
152
 
Zeile 166... Zeile 166...
166
    /**
166
    /**
167
     * @param string $addressLiteral
167
     * @param string $addressLiteral
168
     *
168
     *
169
     * @return bool
169
     * @return bool
170
     */
170
     */
171
    protected function checkIPV4Tag($addressLiteral) : bool
171
    protected function checkIPV4Tag($addressLiteral): bool
172
    {
172
    {
173
        $matchesIP  = [];
173
        $matchesIP  = [];
174
        $IPv4Match = preg_match(self::IPV4_REGEX, $addressLiteral, $matchesIP);
174
        $IPv4Match = preg_match(self::IPV4_REGEX, $addressLiteral, $matchesIP);
Zeile 175... Zeile 175...
175
 
175
 
Zeile 185... Zeile 185...
185
        }
185
        }
Zeile 186... Zeile 186...
186
 
186
 
187
        return true;
187
        return true;
Zeile 188... Zeile 188...
188
    }
188
    }
189
 
189
 
190
    private function addObsoleteWarnings() : void
190
    private function addObsoleteWarnings(): void
191
    {
191
    {
192
        if(in_array($this->lexer->token['type'], self::OBSOLETE_WARNINGS)) {
192
        if (in_array($this->lexer->current->type, self::OBSOLETE_WARNINGS)) {
193
            $this->warnings[ObsoleteDTEXT::CODE] = new ObsoleteDTEXT();
193
            $this->warnings[ObsoleteDTEXT::CODE] = new ObsoleteDTEXT();
Zeile 194... Zeile 194...
194
        }
194
        }
195
    }
195
    }
196
 
196
 
197
    private function addTagWarnings() : void
197
    private function addTagWarnings(): void
198
    {
198
    {
199
        if ($this->lexer->isNextToken(EmailLexer::S_COLON)) {
199
        if ($this->lexer->isNextToken(EmailLexer::S_COLON)) {
Zeile 205... Zeile 205...
205
            if ($lexer->isNextToken(EmailLexer::S_DOUBLECOLON)) {
205
            if ($lexer->isNextToken(EmailLexer::S_DOUBLECOLON)) {
206
                $this->warnings[IPV6ColonStart::CODE] = new IPV6ColonStart();
206
                $this->warnings[IPV6ColonStart::CODE] = new IPV6ColonStart();
207
            }
207
            }
208
        }
208
        }
209
    }
209
    }
210
 
-
 
211
}
210
}