1. sfValidatorBoolean.class.php
  2. /** * sfValidatorBoolean validates a boolean. It also converts the input value to a valid boolean. * * @package symfony * @subpackage validator * @author Fabien Potencier * @version SVN: $Id: sfValidatorBoolean.class.php 10306 2008-07-15 22:12:35Z Carl.Vondrick $ */
  3. class sfValidatorBoolean extends sfValidatorBase
  4. {
  5. /**
  6. * Configures the current validator.
  7. *
  8. * Available options:
  9. *
  10. * * true_values: The list of true values
  11. * * false_values: The list of false values
  12. *
  13. * @param array $options An array of options
  14. * @param array $messages An array of error messages
  15. *
  16. * @see sfValidatorBase
  17. */
  18. protected function configure($options = array(), $messages = array())
  19. {
  20. $this->addOption('true_values', array('true', 't', 'yes', 'y', 'on', '1'));
  21. $this->addOption('false_values', array('false', 'f', 'no', 'n', 'off', '0'));
  22. $this->setOption('required', false);
  23. $this->setOption('empty_value', false);
  24. }
  25. /**
  26. * @see sfValidatorBase
  27. */
  28. protected function doClean($value)
  29. {
  30. if (in_array($value, $this->getOption('true_values')))
  31. {
  32. return true;
  33. }
  34. if (in_array($value, $this->getOption('false_values')))
  35. {
  36. return false;
  37. }
  38. throw new sfValidatorError($this, 'invalid', array('value' => $value));
  39. }
  40. }

Debug toolbar