1. sfValidatorI18nChoiceCountry.class.php
  2. /** * sfValidatorI18nChoiceCountry validates than the value is a valid country. * * @package symfony * @subpackage validator * @author Fabien Potencier * @version SVN: $Id: sfValidatorI18nChoiceCountry.class.php 23940 2009-11-14 17:58:19Z fabien $ */
  3. class sfValidatorI18nChoiceCountry extends sfValidatorChoice
  4. {
  5. /**
  6. * Configures the current validator.
  7. *
  8. * Available options:
  9. *
  10. * * countries: An array of country codes to use (ISO 3166)
  11. *
  12. * @param array $options An array of options
  13. * @param array $messages An array of error messages
  14. *
  15. * @see sfValidatorChoice
  16. */
  17. protected function configure($options = array(), $messages = array())
  18. {
  19. parent::configure($options, $messages);
  20. $this->addOption('countries');
  21. // populate choices with all countries
  22. $countries = array_keys(sfCultureInfo::getInstance()->getCountries());
  23. // restrict countries to a sub-set
  24. if (isset($options['countries']))
  25. {
  26. if ($problems = array_diff($options['countries'], $countries))
  27. {
  28. throw new InvalidArgumentException(sprintf('The following countries do not exist: %s.', implode(', ', $problems)));
  29. }
  30. $countries = $options['countries'];
  31. }
  32. $this->setOption('choices', $countries);
  33. }
  34. }

Debug toolbar