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 30... Zeile 30...
30
     * @var string
30
     * @var string
31
     */
31
     */
32
    private $localPart = '';
32
    private $localPart = '';
Zeile 33... Zeile 33...
33
 
33
 
34
 
34
 
35
    public function parse() : Result
35
    public function parse(): Result
Zeile 36... Zeile 36...
36
    {
36
    {
37
        $this->lexer->startRecording();
37
        $this->lexer->startRecording();
38
 
38
 
39
        while ($this->lexer->token['type'] !== EmailLexer::S_AT && null !== $this->lexer->token['type']) {
39
        while (!$this->lexer->current->isA(EmailLexer::S_AT) && !$this->lexer->current->isA(EmailLexer::S_EMPTY)) {
Zeile 40... Zeile 40...
40
            if ($this->hasDotAtStart()) {
40
            if ($this->hasDotAtStart()) {
41
                return new InvalidEmail(new DotAtStart(), $this->lexer->token['value']);
41
                return new InvalidEmail(new DotAtStart(), $this->lexer->current->value);
Zeile 42... Zeile 42...
42
            }
42
            }
43
 
43
 
44
            if ($this->lexer->token['type'] === EmailLexer::S_DQUOTE) {
44
            if ($this->lexer->current->isA(EmailLexer::S_DQUOTE)) {
45
                $dquoteParsingResult = $this->parseDoubleQuote();
45
                $dquoteParsingResult = $this->parseDoubleQuote();
46
 
46
 
Zeile -... Zeile 47...
-
 
47
                //Invalid double quote parsing
47
                //Invalid double quote parsing
48
                if ($dquoteParsingResult->isInvalid()) {
48
                if($dquoteParsingResult->isInvalid()) {
49
                    return $dquoteParsingResult;
-
 
50
                }
49
                    return $dquoteParsingResult;
51
            }
Zeile 50... Zeile 52...
50
                }
52
 
51
            }
53
            if (
52
 
54
                $this->lexer->current->isA(EmailLexer::S_OPENPARENTHESIS) ||
53
            if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS || 
55
                $this->lexer->current->isA(EmailLexer::S_CLOSEPARENTHESIS)
54
                $this->lexer->token['type'] === EmailLexer::S_CLOSEPARENTHESIS ) {
56
            ) {
Zeile 55... Zeile 57...
55
                $commentsResult = $this->parseComments();
57
                $commentsResult = $this->parseComments();
56
 
58
 
57
                //Invalid comment parsing
59
                //Invalid comment parsing
Zeile -... Zeile 60...
-
 
60
                if ($commentsResult->isInvalid()) {
58
                if($commentsResult->isInvalid()) {
61
                    return $commentsResult;
59
                    return $commentsResult;
62
                }
60
                }
63
            }
61
            }
64
 
62
 
65
            if ($this->lexer->current->isA(EmailLexer::S_DOT) && $this->lexer->isNextToken(EmailLexer::S_DOT)) {
Zeile 63... Zeile 66...
63
            if ($this->lexer->token['type'] === EmailLexer::S_DOT && $this->lexer->isNextToken(EmailLexer::S_DOT)) {
66
                return new InvalidEmail(new ConsecutiveDot(), $this->lexer->current->value);
64
                return new InvalidEmail(new ConsecutiveDot(), $this->lexer->token['value']);
67
            }
65
            }
68
 
Zeile 79... Zeile 82...
79
            if ($resultToken->isInvalid()) {
82
            if ($resultToken->isInvalid()) {
80
                return $resultToken;
83
                return $resultToken;
81
            }
84
            }
Zeile 82... Zeile 85...
82
 
85
 
83
            $resultFWS = $this->parseLocalFWS();
86
            $resultFWS = $this->parseLocalFWS();
84
            if($resultFWS->isInvalid()) {
87
            if ($resultFWS->isInvalid()) {
85
                return $resultFWS;
88
                return $resultFWS;
Zeile 86... Zeile 89...
86
            }
89
            }
87
 
90
 
Zeile 95... Zeile 98...
95
        }
98
        }
Zeile 96... Zeile 99...
96
 
99
 
97
        return new ValidEmail();
100
        return new ValidEmail();
Zeile 98... Zeile 101...
98
    }
101
    }
99
 
102
 
100
    protected function validateTokens(bool $hasComments) : Result
103
    protected function validateTokens(bool $hasComments): Result
101
    {
104
    {
102
        if (isset(self::INVALID_TOKENS[$this->lexer->token['type']])) {
105
        if (isset(self::INVALID_TOKENS[$this->lexer->current->type])) {
103
            return new InvalidEmail(new ExpectingATEXT('Invalid token found'), $this->lexer->token['value']);
106
            return new InvalidEmail(new ExpectingATEXT('Invalid token found'), $this->lexer->current->value);
104
        }
107
        }
Zeile 105... Zeile 108...
105
        return new ValidEmail();
108
        return new ValidEmail();
106
    }
109
    }
107
 
110
 
108
    public function localPart() : string
111
    public function localPart(): string
Zeile 109... Zeile 112...
109
    {
112
    {
110
        return $this->localPart;
113
        return $this->localPart;
111
    }
114
    }
112
 
115
 
113
    private function parseLocalFWS() : Result 
116
    private function parseLocalFWS(): Result
114
    {
117
    {
115
        $foldingWS = new FoldingWhiteSpace($this->lexer);
118
        $foldingWS = new FoldingWhiteSpace($this->lexer);
116
        $resultFWS = $foldingWS->parse();
119
        $resultFWS = $foldingWS->parse();
117
        if ($resultFWS->isValid()) {
120
        if ($resultFWS->isValid()) {
Zeile 118... Zeile 121...
118
            $this->warnings = array_merge($this->warnings, $foldingWS->getWarnings());
121
            $this->warnings = array_merge($this->warnings, $foldingWS->getWarnings());
119
        }
122
        }
120
        return $resultFWS;
123
        return $resultFWS;
121
    }
124
    }
Zeile 122... Zeile 125...
122
 
125
 
123
    private function hasDotAtStart() : bool
126
    private function hasDotAtStart(): bool
124
    {
127
    {
125
            return $this->lexer->token['type'] === EmailLexer::S_DOT && null === $this->lexer->getPrevious()['type'];
128
        return $this->lexer->current->isA(EmailLexer::S_DOT) && $this->lexer->getPrevious()->isA(EmailLexer::S_EMPTY);
126
    }
129
    }
Zeile 137... Zeile 140...
137
    protected function parseComments(): Result
140
    protected function parseComments(): Result
138
    {
141
    {
139
        $commentParser = new Comment($this->lexer, new LocalComment());
142
        $commentParser = new Comment($this->lexer, new LocalComment());
140
        $result = $commentParser->parse();
143
        $result = $commentParser->parse();
141
        $this->warnings = array_merge($this->warnings, $commentParser->getWarnings());
144
        $this->warnings = array_merge($this->warnings, $commentParser->getWarnings());
142
        if($result->isInvalid()) {
145
        if ($result->isInvalid()) {
143
            return $result;
146
            return $result;
144
        }
147
        }
145
        return $result;
148
        return $result;
146
    }
149
    }
Zeile 147... Zeile 150...
147
 
150
 
148
    private function validateEscaping() : Result
151
    private function validateEscaping(): Result
149
    {
152
    {
150
        //Backslash found
153
        //Backslash found
151
        if ($this->lexer->token['type'] !== EmailLexer::S_BACKSLASH) {
154
        if (!$this->lexer->current->isA(EmailLexer::S_BACKSLASH)) {
152
            return new ValidEmail();
155
            return new ValidEmail();
Zeile 153... Zeile 156...
153
        }
156
        }
154
 
157
 
155
        if ($this->lexer->isNextToken(EmailLexer::GENERIC)) {
158
        if ($this->lexer->isNextToken(EmailLexer::GENERIC)) {
Zeile 156... Zeile 159...
156
            return new InvalidEmail(new ExpectingATEXT('Found ATOM after escaping'), $this->lexer->token['value']);
159
            return new InvalidEmail(new ExpectingATEXT('Found ATOM after escaping'), $this->lexer->current->value);
157
        }
160
        }
158
 
161