RFCValidation.php 957 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace Egulias\EmailValidator\Validation;
  3. use Egulias\EmailValidator\EmailLexer;
  4. use Egulias\EmailValidator\EmailParser;
  5. use Egulias\EmailValidator\Exception\InvalidEmail;
  6. class RFCValidation implements EmailValidation
  7. {
  8. /**
  9. * @var EmailParser
  10. */
  11. private $parser;
  12. /**
  13. * @var array
  14. */
  15. private $warnings = [];
  16. /**
  17. * @var InvalidEmail
  18. */
  19. private $error;
  20. public function isValid($email, EmailLexer $emailLexer)
  21. {
  22. $this->parser = new EmailParser($emailLexer);
  23. try {
  24. $this->parser->parse((string)$email);
  25. } catch (InvalidEmail $invalid) {
  26. $this->error = $invalid;
  27. return false;
  28. }
  29. $this->warnings = $this->parser->getWarnings();
  30. return true;
  31. }
  32. public function getError()
  33. {
  34. return $this->error;
  35. }
  36. public function getWarnings()
  37. {
  38. return $this->warnings;
  39. }
  40. }