Validate.php 848B

1234567891011121314151617181920212223242526272829303132333435363738
  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. * @package Swift
  11. * @author Xavier De Cock <xdecock@gmail.com>
  12. */
  13. class Swift_Validate
  14. {
  15. /**
  16. * Grammar Object
  17. * @var Swift_Mime_Grammar
  18. */
  19. private static $grammar = null;
  20. /**
  21. * Checks if an email matches the current grammars
  22. * @param string $email
  23. */
  24. public static function email($email)
  25. {
  26. if (self::$grammar===null)
  27. {
  28. self::$grammar = Swift_DependencyContainer::getInstance()
  29. ->lookup('mime.grammar');
  30. }
  31. return preg_match(
  32. '/^' . self::$grammar->getDefinition('addr-spec') . '$/D',
  33. $email
  34. );
  35. }
  36. }