Validate.php 975B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /*
  3. * This file is part of SwiftMailer.
  4. *
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. */
  8. /**
  9. * Utility Class allowing users to simply check expressions again Swift Grammar.
  10. *
  11. * @package Swift
  12. * @author Xavier De Cock <xdecock@gmail.com>
  13. */
  14. class Swift_Validate
  15. {
  16. /**
  17. * Grammar Object
  18. *
  19. * @var Swift_Mime_Grammar
  20. */
  21. private static $grammar = null;
  22. /**
  23. * Checks if an e-mail address matches the current grammars.
  24. *
  25. * @param string $email
  26. *
  27. * @return boolean
  28. */
  29. public static function email($email)
  30. {
  31. if (self::$grammar===null) {
  32. self::$grammar = Swift_DependencyContainer::getInstance()
  33. ->lookup('mime.grammar');
  34. }
  35. return preg_match(
  36. '/^' . self::$grammar->getDefinition('addr-spec') . '$/D',
  37. $email
  38. );
  39. }
  40. }