Subversion-Projekte lars-tiefland.laravel_shop

Revision

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