sfValidatorCallback.class.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. * sfValidatorCallback validates an input value if the given callback does not throw a sfValidatorError.
  11. *
  12. * @package symfony
  13. * @subpackage validator
  14. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  15. * @version SVN: $Id: sfValidatorCallback.class.php 9048 2008-05-19 09:11:23Z FabianLange $
  16. */
  17. class sfValidatorCallback extends sfValidatorBase
  18. {
  19. /**
  20. * Configures the current validator.
  21. *
  22. * Available options:
  23. *
  24. * * callback: A valid PHP callback (required)
  25. * * arguments: An array of arguments to pass to the callback
  26. *
  27. * @param array $options An array of options
  28. * @param array $messages An array of error messages
  29. *
  30. * @see sfValidatorBase
  31. */
  32. protected function configure($options = array(), $messages = array())
  33. {
  34. $this->addRequiredOption('callback');
  35. $this->addOption('arguments', array());
  36. $this->setOption('required', false);
  37. }
  38. /**
  39. * @see sfValidatorBase
  40. */
  41. protected function doClean($value)
  42. {
  43. return call_user_func($this->getOption('callback'), $this, $value, $this->getOption('arguments'));
  44. }
  45. }