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
2
 
3
namespace Egulias\EmailValidator\Parser;
4
 
5
use Egulias\EmailValidator\EmailLexer;
6
use Egulias\EmailValidator\Result\InvalidEmail;
7
use Egulias\EmailValidator\Result\Reason\ConsecutiveDot;
8
use Egulias\EmailValidator\Result\Result;
9
use Egulias\EmailValidator\Result\ValidEmail;
150 lars 10
use Egulias\EmailValidator\Warning\Warning;
148 lars 11
 
12
abstract class PartParser
13
{
14
    /**
150 lars 15
     * @var Warning[]
148 lars 16
     */
17
    protected $warnings = [];
18
 
19
    /**
20
     * @var EmailLexer
21
     */
22
    protected $lexer;
23
 
24
    public function __construct(EmailLexer $lexer)
25
    {
26
        $this->lexer = $lexer;
27
    }
28
 
150 lars 29
    abstract public function parse(): Result;
148 lars 30
 
31
    /**
150 lars 32
     * @return Warning[]
148 lars 33
     */
34
    public function getWarnings()
35
    {
36
        return $this->warnings;
37
    }
38
 
150 lars 39
    protected function parseFWS(): Result
148 lars 40
    {
41
        $foldingWS = new FoldingWhiteSpace($this->lexer);
42
        $resultFWS = $foldingWS->parse();
43
        $this->warnings = array_merge($this->warnings, $foldingWS->getWarnings());
44
        return $resultFWS;
45
    }
46
 
150 lars 47
    protected function checkConsecutiveDots(): Result
148 lars 48
    {
150 lars 49
        if ($this->lexer->current->isA(EmailLexer::S_DOT) && $this->lexer->isNextToken(EmailLexer::S_DOT)) {
50
            return new InvalidEmail(new ConsecutiveDot(), $this->lexer->current->value);
148 lars 51
        }
52
 
53
        return new ValidEmail();
54
    }
55
 
150 lars 56
    protected function escaped(): bool
148 lars 57
    {
58
        $previous = $this->lexer->getPrevious();
59
 
150 lars 60
        return $previous->isA(EmailLexer::S_BACKSLASH)
61
            && !$this->lexer->current->isA(EmailLexer::GENERIC);
148 lars 62
    }
63
}