You are here

protected function DomainPart::doParseDomainLiteral in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/egulias/email-validator/src/Egulias/EmailValidator/Parser/DomainPart.php \Egulias\EmailValidator\Parser\DomainPart::doParseDomainLiteral()
1 call to DomainPart::doParseDomainLiteral()
DomainPart::parseDomainLiteral in vendor/egulias/email-validator/src/Egulias/EmailValidator/Parser/DomainPart.php

File

vendor/egulias/email-validator/src/Egulias/EmailValidator/Parser/DomainPart.php, line 155

Class

DomainPart

Namespace

Egulias\EmailValidator\Parser

Code

protected function doParseDomainLiteral() {
  $IPv6TAG = false;
  $addressLiteral = '';
  do {
    if ($this->lexer->token['type'] === EmailLexer::C_NUL) {
      throw new \InvalidArgumentException('ERR_EXPECTING_DTEXT');
    }
    if ($this->lexer->token['type'] === EmailLexer::INVALID || $this->lexer->token['type'] === EmailLexer::C_DEL || $this->lexer->token['type'] === EmailLexer::S_LF) {
      $this->warnings[] = EmailValidator::RFC5322_DOMLIT_OBSDTEXT;
    }
    if ($this->lexer
      ->isNextTokenAny(array(
      EmailLexer::S_OPENQBRACKET,
      EmailLexer::S_OPENBRACKET,
    ))) {
      throw new \InvalidArgumentException('ERR_EXPECTING_DTEXT');
    }
    if ($this->lexer
      ->isNextTokenAny(array(
      EmailLexer::S_HTAB,
      EmailLexer::S_SP,
      $this->lexer->token['type'] === EmailLexer::CRLF,
    ))) {
      $this->warnings[] = EmailValidator::CFWS_FWS;
      $this
        ->parseFWS();
    }
    if ($this->lexer
      ->isNextToken(EmailLexer::S_CR)) {
      throw new \InvalidArgumentException("ERR_CR_NO_LF");
    }
    if ($this->lexer->token['type'] === EmailLexer::S_BACKSLASH) {
      $this->warnings[] = EmailValidator::RFC5322_DOMLIT_OBSDTEXT;
      $addressLiteral .= $this->lexer->token['value'];
      $this->lexer
        ->moveNext();
      $this
        ->validateQuotedPair();
    }
    if ($this->lexer->token['type'] === EmailLexer::S_IPV6TAG) {
      $IPv6TAG = true;
    }
    if ($this->lexer->token['type'] === EmailLexer::S_CLOSEQBRACKET) {
      break;
    }
    $addressLiteral .= $this->lexer->token['value'];
  } while ($this->lexer
    ->moveNext());
  $addressLiteral = str_replace('[', '', $addressLiteral);
  $addressLiteral = $this
    ->checkIPV4Tag($addressLiteral);
  if (false === $addressLiteral) {
    return $addressLiteral;
  }
  if (!$IPv6TAG) {
    $this->warnings[] = EmailValidator::RFC5322_DOMAINLITERAL;
    return $addressLiteral;
  }
  $this->warnings[] = EmailValidator::RFC5321_ADDRESSLITERAL;
  $this
    ->checkIPV6Tag($addressLiteral);
  return $addressLiteral;
}