[ Index ] |
|
Code source de LifeType 1.2.4 |
1 <?php 2 3 lt_include( PLOG_CLASS_PATH."class/data/validator/rules/rule.class.php"); 4 5 define( "ERROR_RULE_INTEGER_TOO_SMALL", "error_rule_integer_too_small"); 6 define( "ERROR_RULE_INTEGER_TOO_LARGE", "error_rule_integer_too_large"); 7 8 /** 9 * \ingroup Validator_Rules 10 * 11 * Given two values that will be used as lower and upper boundaries of the range, 12 * it will validate whether the given value falls within the range. 13 * 14 * It will set the errors ERROR_RULE_INTEGER_TOO_SMALL or ERROR_RULE_INTEGER_TOO_LARGE in case the 15 * validation is not successful. 16 */ 17 class IntRangeRule extends Rule 18 { 19 var $_minValue; 20 var $_maxValue; 21 22 /** 23 * Initializes the rule 24 * 25 * @param minValue the lower boundary of the range 26 * @param maxValue the upper boundary of the range 27 */ 28 function IntRangeRule($minValue, $maxValue) 29 { 30 $this->Rule(); 31 32 $this->_minValue = $minValue; 33 $this->_maxValue = $maxValue; 34 } 35 36 /** 37 * @return the lower boundary of the range 38 */ 39 function getMinValue() 40 { 41 return $this->_minValue; 42 } 43 44 /** 45 * sets the lower boundary of the range 46 * 47 * @param minValue the minimum value 48 */ 49 function setMinValue($minValue) 50 { 51 $this->_minValue = $minValue; 52 } 53 54 /** 55 * @return the upper boundary of the range 56 */ 57 function getMaxValue() 58 { 59 return $this->_maxValue; 60 } 61 62 /** 63 * sets the lower boundary of the range 64 * 65 * @param minValue the minimum value 66 */ 67 function setMaxValue($maxValue) 68 { 69 $this->_maxValue = $maxValue; 70 } 71 72 /** 73 * validates that the given value is within the two boundaries previously specified 74 * 75 * @param value The value to validate 76 * @return True if successful or false otherwise 77 */ 78 function validate($value) 79 { 80 //$len = strlen($value); 81 $intValue = (int)$value; 82 83 if ($intValue < $this->_minValue) 84 { 85 $this->_setError(ERROR_RULE_INTEGER_TOO_SMALL); 86 return false; 87 } 88 else if ($this->_maxValue != 0 && $intValue > $this->_maxValue) 89 { 90 $this->_setError(ERROR_RULE_INTEGER_TOO_LARGE); 91 return false; 92 } 93 else 94 { 95 $this->_setError(false); 96 return true; 97 } 98 } 99 } 100 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 21:04:15 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |