Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. DomainPart.php

function DomainPart::doParseDomainPart

1 call to DomainPart::doParseDomainPart()
DomainPart::parse in vendor/egulias/email-validator/src/Parser/DomainPart.php

File

vendor/egulias/email-validator/src/Parser/DomainPart.php, line 145

Class

DomainPart

Namespace

Egulias\EmailValidator\Parser

Code

protected function doParseDomainPart() : Result {
    $tldMissing = true;
    $hasComments = false;
    $domain = '';
    do {
        $prev = $this->lexer
            ->getPrevious();
        $notAllowedChars = $this->checkNotAllowedChars($this->lexer->current);
        if ($notAllowedChars->isInvalid()) {
            return $notAllowedChars;
        }
        if ($this->lexer->current
            ->isA(EmailLexer::S_OPENPARENTHESIS) || $this->lexer->current
            ->isA(EmailLexer::S_CLOSEPARENTHESIS)) {
            $hasComments = true;
            $commentsResult = $this->parseComments();
            
            //Invalid comment parsing
            if ($commentsResult->isInvalid()) {
                return $commentsResult;
            }
        }
        $dotsResult = $this->checkConsecutiveDots();
        if ($dotsResult->isInvalid()) {
            return $dotsResult;
        }
        if ($this->lexer->current
            ->isA(EmailLexer::S_OPENBRACKET)) {
            $literalResult = $this->parseDomainLiteral();
            $this->addTLDWarnings($tldMissing);
            return $literalResult;
        }
        $labelCheck = $this->checkLabelLength();
        if ($labelCheck->isInvalid()) {
            return $labelCheck;
        }
        $FwsResult = $this->parseFWS();
        if ($FwsResult->isInvalid()) {
            return $FwsResult;
        }
        $domain .= $this->lexer->current->value;
        if ($this->lexer->current
            ->isA(EmailLexer::S_DOT) && $this->lexer
            ->isNextToken(EmailLexer::GENERIC)) {
            $tldMissing = false;
        }
        $exceptionsResult = $this->checkDomainPartExceptions($prev, $hasComments);
        if ($exceptionsResult->isInvalid()) {
            return $exceptionsResult;
        }
        $this->lexer
            ->moveNext();
    } while (!$this->lexer->current
        ->isA(EmailLexer::S_EMPTY));
    $labelCheck = $this->checkLabelLength(true);
    if ($labelCheck->isInvalid()) {
        return $labelCheck;
    }
    $this->addTLDWarnings($tldMissing);
    $this->domainPart = $domain;
    return new ValidEmail();
}
RSS feed
Powered by Drupal