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

Breadcrumb

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

class EmailParser

Hierarchy

  • class \Egulias\EmailValidator\Parser
    • class \Egulias\EmailValidator\EmailParser extends \Egulias\EmailValidator\Parser

Expanded class hierarchy of EmailParser

2 files declare their use of EmailParser
EmailTooLong.php in vendor/egulias/email-validator/src/Warning/EmailTooLong.php
RFCValidation.php in vendor/egulias/email-validator/src/Validation/RFCValidation.php

File

vendor/egulias/email-validator/src/EmailParser.php, line 13

Namespace

Egulias\EmailValidator
View source
class EmailParser extends Parser {
    public const EMAIL_MAX_LENGTH = 254;
    
    /**
     * @var string
     */
    protected $domainPart = '';
    
    /**
     * @var string
     */
    protected $localPart = '';
    public function parse(string $str) : Result {
        $result = parent::parse($str);
        $this->addLongEmailWarning($this->localPart, $this->domainPart);
        return $result;
    }
    protected function preLeftParsing() : Result {
        if (!$this->hasAtToken()) {
            return new InvalidEmail(new NoLocalPart(), $this->lexer->current->value);
        }
        return new ValidEmail();
    }
    protected function parseLeftFromAt() : Result {
        return $this->processLocalPart();
    }
    protected function parseRightFromAt() : Result {
        return $this->processDomainPart();
    }
    private function processLocalPart() : Result {
        $localPartParser = new LocalPart($this->lexer);
        $localPartResult = $localPartParser->parse();
        $this->localPart = $localPartParser->localPart();
        $this->warnings = [
            $localPartParser->getWarnings(),
            $this->warnings,
        ];
        return $localPartResult;
    }
    private function processDomainPart() : Result {
        $domainPartParser = new DomainPart($this->lexer);
        $domainPartResult = $domainPartParser->parse();
        $this->domainPart = $domainPartParser->domainPart();
        $this->warnings = [
            $domainPartParser->getWarnings(),
            $this->warnings,
        ];
        return $domainPartResult;
    }
    public function getDomainPart() : string {
        return $this->domainPart;
    }
    public function getLocalPart() : string {
        return $this->localPart;
    }
    private function addLongEmailWarning(string $localPart, string $parsedDomainPart) : void {
        if (strlen($localPart . '@' . $parsedDomainPart) > self::EMAIL_MAX_LENGTH) {
            $this->warnings[EmailTooLong::CODE] = new EmailTooLong();
        }
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
EmailParser::$domainPart protected property
EmailParser::$localPart protected property
EmailParser::addLongEmailWarning private function
EmailParser::EMAIL_MAX_LENGTH public constant
EmailParser::getDomainPart public function
EmailParser::getLocalPart public function
EmailParser::parse public function Overrides Parser::parse
EmailParser::parseLeftFromAt protected function Overrides Parser::parseLeftFromAt
EmailParser::parseRightFromAt protected function id-left "@" id-right Overrides Parser::parseRightFromAt
EmailParser::preLeftParsing protected function Overrides Parser::preLeftParsing
EmailParser::processDomainPart private function
EmailParser::processLocalPart private function
Parser::$lexer protected property
Parser::$warnings protected property
Parser::getWarnings public function
Parser::hasAtToken protected function
Parser::__construct public function
RSS feed
Powered by Drupal