You are here

abstract class Parser in Zircon Profile 8.0

Same name in this branch
  1. 8.0 vendor/symfony/yaml/Parser.php \Symfony\Component\Yaml\Parser
  2. 8.0 vendor/sebastian/diff/src/Parser.php \SebastianBergmann\Diff\Parser
  3. 8.0 vendor/symfony/css-selector/Parser/Parser.php \Symfony\Component\CssSelector\Parser\Parser
  4. 8.0 vendor/egulias/email-validator/src/Egulias/EmailValidator/Parser/Parser.php \Egulias\EmailValidator\Parser\Parser
Same name and namespace in other branches
  1. 8 vendor/egulias/email-validator/src/Egulias/EmailValidator/Parser/Parser.php \Egulias\EmailValidator\Parser\Parser

Hierarchy

  • class \Egulias\EmailValidator\Parser\Parser

Expanded class hierarchy of Parser

1 file declares its use of Parser
DomainPart.php in vendor/egulias/email-validator/src/Egulias/EmailValidator/Parser/DomainPart.php
2 string references to 'Parser'
aggregator.schema.yml in core/modules/aggregator/config/schema/aggregator.schema.yml
core/modules/aggregator/config/schema/aggregator.schema.yml
SettingsForm::buildForm in core/modules/aggregator/src/Form/SettingsForm.php
Form constructor.

File

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

Namespace

Egulias\EmailValidator\Parser
View source
abstract class Parser {
  protected $warnings = array();
  protected $lexer;
  public function __construct(EmailLexer $lexer) {
    $this->lexer = $lexer;
  }
  public function getWarnings() {
    return $this->warnings;
  }
  abstract function parse($str);

  /**
   * validateQuotedPair
   */
  protected function validateQuotedPair() {
    if (!($this->lexer->token['type'] === EmailLexer::INVALID || $this->lexer->token['type'] === EmailLexer::C_DEL)) {
      throw new \InvalidArgumentException('ERR_EXPECTING_QPAIR');
    }
    $this->warnings[] = EmailValidator::DEPREC_QP;
  }

  /**
   * @return string the the comment
   * @throws \InvalidArgumentException
   */
  protected function parseComments() {
    $this
      ->isUnclosedComment();
    $this->warnings[] = EmailValidator::CFWS_COMMENT;
    while (!$this->lexer
      ->isNextToken(EmailLexer::S_CLOSEPARENTHESIS)) {
      $this
        ->warnEscaping();
      $this->lexer
        ->moveNext();
    }
    $this->lexer
      ->moveNext();
    if ($this->lexer
      ->isNextTokenAny(array(
      EmailLexer::GENERIC,
      EmailLexer::S_EMPTY,
    ))) {
      throw new \InvalidArgumentException('ERR_EXPECTING_ATEXT');
    }
    if ($this->lexer
      ->isNextToken(EmailLexer::S_AT)) {
      $this->warnings[] = EmailValidator::DEPREC_CFWS_NEAR_AT;
    }
  }
  protected function isUnclosedComment() {
    try {
      $this->lexer
        ->find(EmailLexer::S_CLOSEPARENTHESIS);
      return true;
    } catch (\RuntimeException $e) {
      throw new \InvalidArgumentException('ERR_UNCLOSEDCOMMENT');
    }
  }
  protected function parseFWS() {
    $previous = $this->lexer
      ->getPrevious();
    $this
      ->checkCRLFInFWS();
    if ($this->lexer->token['type'] === EmailLexer::S_CR) {
      throw new \InvalidArgumentException("ERR_CR_NO_LF");
    }
    if ($this->lexer
      ->isNextToken(EmailLexer::GENERIC) && $previous['type'] !== EmailLexer::S_AT) {
      throw new \InvalidArgumentException("ERR_ATEXT_AFTER_CFWS");
    }
    if ($this->lexer->token['type'] === EmailLexer::S_LF || $this->lexer->token['type'] === EmailLexer::C_NUL) {
      throw new \InvalidArgumentException('ERR_EXPECTING_CTEXT');
    }
    if ($this->lexer
      ->isNextToken(EmailLexer::S_AT) || $previous['type'] === EmailLexer::S_AT) {
      $this->warnings[] = EmailValidator::DEPREC_CFWS_NEAR_AT;
    }
    else {
      $this->warnings[] = EmailValidator::CFWS_FWS;
    }
  }
  protected function checkConsecutiveDots() {
    if ($this->lexer->token['type'] === EmailLexer::S_DOT && $this->lexer
      ->isNextToken(EmailLexer::S_DOT)) {
      throw new \InvalidArgumentException('ERR_CONSECUTIVEDOTS');
    }
  }
  protected function isFWS() {
    if ($this
      ->escaped()) {
      return false;
    }
    if ($this->lexer->token['type'] === EmailLexer::S_SP || $this->lexer->token['type'] === EmailLexer::S_HTAB || $this->lexer->token['type'] === EmailLexer::S_CR || $this->lexer->token['type'] === EmailLexer::S_LF || $this->lexer->token['type'] === EmailLexer::CRLF) {
      return true;
    }
    return false;
  }
  protected function escaped() {
    $previous = $this->lexer
      ->getPrevious();
    if ($previous['type'] === EmailLexer::S_BACKSLASH && $this->lexer->token['type'] !== EmailLexer::GENERIC) {
      return true;
    }
    return false;
  }
  protected function warnEscaping() {
    if ($this->lexer->token['type'] !== EmailLexer::S_BACKSLASH) {
      return false;
    }
    if ($this->lexer
      ->isNextToken(EmailLexer::GENERIC)) {
      throw new \InvalidArgumentException('ERR_EXPECTING_ATEXT');
    }
    if (!$this->lexer
      ->isNextTokenAny(array(
      EmailLexer::S_SP,
      EmailLexer::S_HTAB,
      EmailLexer::C_DEL,
    ))) {
      return false;
    }
    $this->warnings[] = EmailValidator::DEPREC_QP;
    return true;
  }
  protected function checkDQUOTE($hasClosingQuote) {
    if ($this->lexer->token['type'] !== EmailLexer::S_DQUOTE) {
      return $hasClosingQuote;
    }
    if ($hasClosingQuote) {
      return $hasClosingQuote;
    }
    $previous = $this->lexer
      ->getPrevious();
    if ($this->lexer
      ->isNextToken(EmailLexer::GENERIC) && $previous['type'] === EmailLexer::GENERIC) {
      throw new \InvalidArgumentException('ERR_EXPECTING_ATEXT');
    }
    $this->warnings[] = EmailValidator::RFC5321_QUOTEDSTRING;
    try {
      $this->lexer
        ->find(EmailLexer::S_DQUOTE);
      $hasClosingQuote = true;
    } catch (\Exception $e) {
      throw new \InvalidArgumentException('ERR_UNCLOSEDQUOTEDSTR');
    }
    return $hasClosingQuote;
  }
  protected function checkCRLFInFWS() {
    if ($this->lexer->token['type'] !== EmailLexer::CRLF) {
      return;
    }
    if ($this->lexer
      ->isNextToken(EmailLexer::CRLF)) {
      throw new \InvalidArgumentException("ERR_FWS_CRLF_X2");
    }
    if (!$this->lexer
      ->isNextTokenAny(array(
      EmailLexer::S_SP,
      EmailLexer::S_HTAB,
    ))) {
      throw new \InvalidArgumentException("ERR_FWS_CRLF_END");
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
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::parse abstract function 2
Parser::parseComments protected function
Parser::parseFWS protected function
Parser::validateQuotedPair protected function validateQuotedPair
Parser::warnEscaping protected function
Parser::__construct public function