1. sfValidatorUrl.class.php
  2. /** * sfValidatorUrl validates Urls. * * @package symfony * @subpackage validator * @author Fabien Potencier * @version SVN: $Id: sfValidatorUrl.class.php 22149 2009-09-18 14:09:53Z Kris.Wallsmith $ */
  3. class sfValidatorUrl extends sfValidatorRegex
  4. {
  5. const REGEX_URL_FORMAT = '~^
  6. (%s):// # protocol
  7. (
  8. ([a-z0-9-]+\.)+[a-z]{2,6} # a domain name
  9. | # or
  10. \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} # a IP address
  11. )
  12. (:[0-9]+)? # a port (optional)
  13. (/?|/\S+) # a /, nothing or a / with something
  14. $~ix';
  15. /**
  16. * Available options:
  17. *
  18. * * protocols: An array of acceptable URL protocols (http, https, ftp and ftps by default)
  19. *
  20. * @param array $options An array of options
  21. * @param array $messages An array of error messages
  22. *
  23. * @see sfValidatorRegex
  24. */
  25. protected function configure($options = array(), $messages = array())
  26. {
  27. parent::configure($options, $messages);
  28. $this->addOption('protocols', array('http', 'https', 'ftp', 'ftps'));
  29. $this->setOption('pattern', new sfCallable(array($this, 'generateRegex')));
  30. }
  31. /**
  32. * Generates the current validator's regular expression.
  33. *
  34. * @return string
  35. */
  36. public function generateRegex()
  37. {
  38. return sprintf(self::REGEX_URL_FORMAT, implode('|', $this->getOption('protocols')));
  39. }
  40. }

Debug toolbar