1. sfValidatorSchemaFilter.class.php
  2. /** * sfValidatorSchemaFilter executes non schema validator on a schema input value. * * @package symfony * @subpackage validator * @author Fabien Potencier * @version SVN: $Id: sfValidatorSchemaFilter.class.php 21908 2009-09-11 12:06:21Z fabien $ */
  3. class sfValidatorSchemaFilter extends sfValidatorSchema
  4. {
  5. /**
  6. * Constructor.
  7. *
  8. * @param string $field The field name
  9. * @param sfValidatorBase $validator The validator
  10. * @param array $options An array of options
  11. * @param array $messages An array of error messages
  12. *
  13. * @see sfValidatorBase
  14. */
  15. public function __construct($field, sfValidatorBase $validator, $options = array(), $messages = array())
  16. {
  17. $this->addOption('field', $field);
  18. $this->addOption('validator', $validator);
  19. parent::__construct(null, $options, $messages);
  20. }
  21. /**
  22. * @see sfValidatorBase
  23. */
  24. protected function doClean($values)
  25. {
  26. if (null === $values)
  27. {
  28. $values = array();
  29. }
  30. if (!is_array($values))
  31. {
  32. throw new InvalidArgumentException('You must pass an array parameter to the clean() method');
  33. }
  34. $value = isset($values[$this->getOption('field')]) ? $values[$this->getOption('field')] : null;
  35. try
  36. {
  37. $values[$this->getOption('field')] = $this->getOption('validator')->clean($value);
  38. }
  39. catch (sfValidatorError $error)
  40. {
  41. throw new sfValidatorErrorSchema($this, array($this->getOption('field') => $error));
  42. }
  43. return $values;
  44. }
  45. /**
  46. * @see sfValidatorBase
  47. */
  48. public function asString($indent = 0)
  49. {
  50. return sprintf('%s%s:%s', str_repeat(' ', $indent), $this->getOption('field'), $this->getOption('validator')->asString(0));
  51. }
  52. }

Debug toolbar