Source for file BooleanValidatorRule.class.php

Documentation is available at BooleanValidatorRule.class.php

  1. <?php
  2.  
  3. require_once(HARMONI."utilities/FieldSetValidator/rules/ValidatorRule.interface.php");
  4.  
  5. /**
  6. * the BooleanValidatorRule checks a given value to make sure it's a boolean value
  7. *
  8. * @package harmoni.utilities.fieldsetvalidator.rules
  9. *
  10. * @copyright Copyright &copy; 2005, Middlebury College
  11. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  12. *
  13. * @version $Id: BooleanValidatorRule.class.php,v 1.5 2007/09/04 20:25:55 adamfranco Exp $
  14. */
  15. class BooleanValidatorRule
  16. extends ValidatorRuleInterface
  17. {
  18. /**
  19. * checks a given value to make sure it's boolean
  20. * @param mixed $val the value to check
  21. * @access public
  22. * @return boolean true if the value is boolean, false if it is not
  23. ***/
  24. function check( $val ) {
  25. if (is_bool($val)) return true;
  26. return false;
  27. }
  28. /**
  29. * This is a static method to return an already-created instance of a validator
  30. * rule. There are at most about a hundred unique rule objects in use durring
  31. * any given execution cycle, but rule objects are instantiated hundreds of
  32. * thousands of times.
  33. *
  34. * This method follows a modified Singleton pattern
  35. *
  36. * @return object ValidatorRule
  37. * @access public
  38. * @static
  39. * @since 3/28/05
  40. */
  41. function getRule () {
  42. // Because there is no way in PHP to get the class name of the descendent
  43. // class on which this method is called, this method must be implemented
  44. // in each descendent class.
  45.  
  46. if (!isset($GLOBALS['validator_rules']) || !is_array($GLOBALS['validator_rules']))
  47. $GLOBALS['validator_rules'] = array();
  48. $class = __CLASS__;
  49. if (!isset($GLOBALS['validator_rules'][$class]))
  50. $GLOBALS['validator_rules'][$class] = new $class;
  51. return $GLOBALS['validator_rules'][$class];
  52. }
  53. }
  54.  
  55. ?>

Documentation generated on Wed, 19 Sep 2007 10:21:47 -0400 by phpDocumentor 1.3.0RC3