mirror of
https://github.com/egulias/EmailValidator.git
synced 2026-08-24 00:58:21 +00:00
Message-id validator (#290)
* scafolding for MessageID validation * Improve domain valid tokens * Improved EmailParser to remove leaked logic. User of lexer recorder within parsers. * MessageIDParser passing tests. * change left for right, which is the right one * psaml errors * Better naming * comments are not allowed in IDLeft for message-id * Suppress psalm inheritance over tokens and dependencies * Update src/Parser.php Co-authored-by: Alexander M. Turek <me@derrabus.de> * Update src/Parser.php Co-authored-by: Alexander M. Turek <me@derrabus.de> * improve parser from comments Co-authored-by: Alexander M. Turek <me@derrabus.de>
This commit is contained in:
committed by
GitHub
parent
451b438902
commit
8e526a57c1
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Validation;
|
||||
|
||||
use Egulias\EmailValidator\EmailLexer;
|
||||
use Egulias\EmailValidator\MessageIDParser;
|
||||
use Egulias\EmailValidator\Result\InvalidEmail;
|
||||
use Egulias\EmailValidator\Result\Reason\ExceptionFound;
|
||||
|
||||
class MessageIDValidation implements EmailValidation
|
||||
{
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $warnings = [];
|
||||
|
||||
/**
|
||||
* @var ?InvalidEmail
|
||||
*/
|
||||
private $error;
|
||||
|
||||
public function isValid(string $email, EmailLexer $emailLexer): bool
|
||||
{
|
||||
$parser = new MessageIDParser($emailLexer);
|
||||
try {
|
||||
$result = $parser->parse($email);
|
||||
$this->warnings = $parser->getWarnings();
|
||||
if ($result->isInvalid()) {
|
||||
/** @psalm-suppress PropertyTypeCoercion */
|
||||
$this->error = $result;
|
||||
return false;
|
||||
}
|
||||
} catch (\Exception $invalid) {
|
||||
$this->error = new InvalidEmail(new ExceptionFound($invalid), '');
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getWarnings(): array
|
||||
{
|
||||
return $this->warnings;
|
||||
}
|
||||
|
||||
public function getError(): ?InvalidEmail
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user