You are here

class LocalPart in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/egulias/email-validator/src/Egulias/EmailValidator/Parser/LocalPart.php \Egulias\EmailValidator\Parser\LocalPart

Hierarchy

  • class \Egulias\EmailValidator\Parser\Parser
    • class \Egulias\EmailValidator\Parser\LocalPart

Expanded class hierarchy of LocalPart

1 file declares its use of LocalPart
EmailParser.php in vendor/egulias/email-validator/src/Egulias/EmailValidator/EmailParser.php

File

vendor/egulias/email-validator/src/Egulias/EmailValidator/Parser/LocalPart.php, line 9

Namespace

Egulias\EmailValidator\Parser
View source
class LocalPart extends Parser {
  public function parse($localPart) {
    $parseDQuote = true;
    $closingQuote = false;
    while ($this->lexer->token['type'] !== EmailLexer::S_AT && $this->lexer->token) {
      if ($this->lexer->token['type'] === EmailLexer::S_DOT && !$this->lexer
        ->getPrevious()) {
        throw new \InvalidArgumentException('ERR_DOT_START');
      }
      $closingQuote = $this
        ->checkDQUOTE($closingQuote);
      if ($closingQuote && $parseDQuote) {
        $parseDQuote = $this
          ->parseDoubleQuote();
      }
      if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS) {
        $this
          ->parseComments();
      }
      $this
        ->checkConsecutiveDots();
      if ($this->lexer->token['type'] === EmailLexer::S_DOT && $this->lexer
        ->isNextToken(EmailLexer::S_AT)) {
        throw new \InvalidArgumentException('ERR_DOT_END');
      }
      $this
        ->warnEscaping();
      $this
        ->isInvalidToken($this->lexer->token, $closingQuote);
      if ($this
        ->isFWS()) {
        $this
          ->parseFWS();
      }
      $this->lexer
        ->moveNext();
    }
    $prev = $this->lexer
      ->getPrevious();
    if (strlen($prev['value']) > EmailValidator::RFC5322_LOCAL_TOOLONG) {
      $this->warnings[] = EmailValidator::RFC5322_LOCAL_TOOLONG;
    }
  }
  protected function parseDoubleQuote() {
    $parseAgain = true;
    $special = array(
      EmailLexer::S_CR => true,
      EmailLexer::S_HTAB => true,
      EmailLexer::S_LF => true,
    );
    $invalid = array(
      EmailLexer::C_NUL => true,
      EmailLexer::S_HTAB => true,
      EmailLexer::S_CR => true,
      EmailLexer::S_LF => true,
    );
    $setSpecialsWarning = true;
    $this->lexer
      ->moveNext();
    while ($this->lexer->token['type'] !== EmailLexer::S_DQUOTE && $this->lexer->token) {
      $parseAgain = false;
      if (isset($special[$this->lexer->token['type']]) && $setSpecialsWarning) {
        $this->warnings[] = EmailValidator::CFWS_FWS;
        $setSpecialsWarning = false;
      }
      $this->lexer
        ->moveNext();
      if (!$this
        ->escaped() && isset($invalid[$this->lexer->token['type']])) {
        throw new InvalidArgumentException("ERR_EXPECTED_ATEXT");
      }
    }
    $prev = $this->lexer
      ->getPrevious();
    if ($prev['type'] === EmailLexer::S_BACKSLASH) {
      if (!$this
        ->checkDQUOTE(false)) {
        throw new \InvalidArgumentException("ERR_UNCLOSED_DQUOTE");
      }
    }
    if (!$this->lexer
      ->isNextToken(EmailLexer::S_AT) && $prev['type'] !== EmailLexer::S_BACKSLASH) {
      throw new \InvalidArgumentException("ERR_EXPECED_AT");
    }
    return $parseAgain;
  }
  protected function isInvalidToken($token, $closingQuote) {
    $forbidden = array(
      EmailLexer::S_COMMA,
      EmailLexer::S_CLOSEBRACKET,
      EmailLexer::S_OPENBRACKET,
      EmailLexer::S_GREATERTHAN,
      EmailLexer::S_LOWERTHAN,
      EmailLexer::S_COLON,
      EmailLexer::S_SEMICOLON,
      EmailLexer::INVALID,
    );
    if (in_array($token['type'], $forbidden) && !$closingQuote) {
      throw new \InvalidArgumentException('ERR_EXPECTING_ATEXT');
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LocalPart::isInvalidToken protected function
LocalPart::parse public function Overrides Parser::parse
LocalPart::parseDoubleQuote protected function
Parser::$lexer protected property
Parser::$warnings protected property
Parser::checkConsecutiveDots protected function
Parser::checkCRLFInFWS protected function
Parser::checkDQUOTE protected function
Parser::escaped protected function
Parser::getWarnings public function
Parser::isFWS protected function
Parser::isUnclosedComment protected function
Parser::parseComments protected function
Parser::parseFWS protected function
Parser::validateQuotedPair protected function validateQuotedPair
Parser::warnEscaping protected function
Parser::__construct public function