sfValidatorCallback.class.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. }