Source for file IntegerRangeValidatorRule.class.php

Documentation is available at IntegerRangeValidatorRule.class.php

  1. <?php
  2.  
  3. require_once(HARMONI."utilities/FieldSetValidator/rules/ValidatorRule.interface.php");
  4.  
  5. /**
  6. * the IntegerRangeValidatorRule checks a given value to make sure it's integer that
  7. * falls within a certain range.
  8. *
  9. * @package harmoni.utilities.fieldsetvalidator.rules
  10. *
  11. * @copyright Copyright &copy; 2005, Middlebury College
  12. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  13. *
  14. * @version $Id: IntegerRangeValidatorRule.class.php,v 1.8 2007/09/04 20:25:55 adamfranco Exp $
  15. */
  16. class IntegerRangeValidatorRule
  17. extends ValidatorRuleInterface
  18. {
  19.  
  20. /**
  21. * The range min.
  22. * @var integer _mix
  23. * @access private
  24. */
  25. var $_mix;
  26. /**
  27. * The range max.
  28. * @var integer _max
  29. * @access private
  30. */
  31. var $_max;
  32.  
  33. /**
  34. * Initializes the rule
  35. * @access public
  36. */
  37. function IntegerRangeValidatorRule($min, $max) {
  38. $this->_min = $min;
  39. $this->_max = $max;
  40. }
  41. /**
  42. * Checks a given value to make sure it's an integer.
  43. * Checks a given value to make sure it's an integer.
  44. * @param mixed $val The value to check.
  45. * @access public
  46. * @return boolean TRUE, if the value is an integer; FALSE if it is not.
  47. ***/
  48. function check( $val ) {
  49. // if (!(is_integer($val) || $val === 0))
  50. // return false;
  51. // print "checking $val against $this->_min to $this->_max<br>";
  52. return ($val >= $this->_min && $val <= $this->_max);
  53. }
  54. /**
  55. * This is a static method to return an already-created instance of a validator
  56. * rule. There are at most about a hundred unique rule objects in use durring
  57. * any given execution cycle, but rule objects are instantiated hundreds of
  58. * thousands of times.
  59. *
  60. * This method follows a modified Singleton pattern
  61. *
  62. * @return object ValidatorRule
  63. * @access public
  64. * @static
  65. * @since 3/28/05
  66. */
  67. function getRule ($min, $max) {
  68. // Because there is no way in PHP to get the class name of the descendent
  69. // class on which this method is called, this method must be implemented
  70. // in each descendent class.
  71.  
  72. if (!isset($GLOBALS['validator_rules']) || !is_array($GLOBALS['validator_rules']))
  73. $GLOBALS['validator_rules'] = array();
  74. $class = __CLASS__;
  75. $ruleKey = $class."(".$min.", ".$max.")";
  76. if (!isset($GLOBALS['validator_rules'][$ruleKey]))
  77. $GLOBALS['validator_rules'][$ruleKey] = new $class($min, $max);
  78. return $GLOBALS['validator_rules'][$ruleKey];
  79. }
  80. /**
  81. * Return a key that can be used to identify this Rule for caching purposes.
  82. * If this rule takes no arguments, the class name should be sufficient.
  83. * otherwise, append the arguments.
  84. *
  85. * This method should only be called by ValidatorRules.
  86. *
  87. * @return string
  88. * @access protected
  89. * @since 3/29/05
  90. */
  91. function getRuleKey () {
  92. return get_class($this)."(".$this->_min.", ".$this->_max.")";
  93. }
  94. }
  95.  
  96. ?>

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