first commit
This commit is contained in:
54
vendor/egulias/email-validator/src/Validation/RFCValidation.php
vendored
Normal file
54
vendor/egulias/email-validator/src/Validation/RFCValidation.php
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Validation;
|
||||
|
||||
use Egulias\EmailValidator\EmailLexer;
|
||||
use Egulias\EmailValidator\EmailParser;
|
||||
use Egulias\EmailValidator\Result\InvalidEmail;
|
||||
use Egulias\EmailValidator\Result\Reason\ExceptionFound;
|
||||
use Egulias\EmailValidator\Warning\Warning;
|
||||
|
||||
class RFCValidation implements EmailValidation
|
||||
{
|
||||
/**
|
||||
* @var Warning[]
|
||||
*/
|
||||
private array $warnings = [];
|
||||
|
||||
/**
|
||||
* @var ?InvalidEmail
|
||||
*/
|
||||
private $error;
|
||||
|
||||
public function isValid(string $email, EmailLexer $emailLexer): bool
|
||||
{
|
||||
$parser = new EmailParser($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 getError(): ?InvalidEmail
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Warning[]
|
||||
*/
|
||||
public function getWarnings(): array
|
||||
{
|
||||
return $this->warnings;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user