sfValidatorChoiceMany.class.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /*
  3. * This file is part of the symfony package.
  4. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. /**
  10. * sfValidatorChoiceMany validates than an array of values is in the array of the expected values.
  11. *
  12. * @package symfony
  13. * @subpackage validator
  14. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  15. * @version SVN: $Id: sfValidatorChoiceMany.class.php 11612 2008-09-17 15:28:38Z nicolas $
  16. */
  17. class sfValidatorChoiceMany extends sfValidatorChoice
  18. {
  19. /**
  20. * @see sfValidatorBase
  21. */
  22. protected function doClean($values)
  23. {
  24. if (!is_array($values))
  25. {
  26. $values = array($values);
  27. }
  28. $choices = $this->getOption('choices');
  29. if ($choices instanceof sfCallable)
  30. {
  31. $choices = $choices->call();
  32. }
  33. foreach ($values as $value)
  34. {
  35. if (!parent::inChoices($value, $choices))
  36. {
  37. throw new sfValidatorError($this, 'invalid', array('value' => $value));
  38. }
  39. }
  40. return $values;
  41. }
  42. }