Index: trunk/extensions/Validator/includes/criteria/CriterionHasLength.php |
— | — | @@ -36,11 +36,7 @@ |
37 | 37 | */ |
38 | 38 | public function validate( $value ) { |
39 | 39 | $strlen = strlen( $value ); |
40 | | - |
41 | | - if ( $strlen > $this->upperBound ) return false; |
42 | | - if ( $strlen < $this->lowerBound ) return false; |
43 | | - |
44 | | - return true; |
| 40 | + return $strlen <= $this->upperBound && $strlen >= $this->lowerBound; |
45 | 41 | } |
46 | 42 | |
47 | 43 | } |
\ No newline at end of file |
Index: trunk/extensions/Validator/includes/criteria/CriterionInRange.php |
— | — | @@ -13,20 +13,35 @@ |
14 | 14 | */ |
15 | 15 | class CriterionInRange extends ParameterCriterion { |
16 | 16 | |
| 17 | + protected $lowerBound; |
| 18 | + protected $upperBound; |
| 19 | + |
17 | 20 | /** |
18 | 21 | * Constructor. |
19 | 22 | * |
| 23 | + * @param integer $lowerBound |
| 24 | + * @param integer $upperBound |
| 25 | + * |
20 | 26 | * @since 0.4 |
21 | 27 | */ |
22 | | - public function __construct( ) { |
| 28 | + public function __construct( $lowerBound, $upperBound ) { |
23 | 29 | parent::__construct(); |
| 30 | + |
| 31 | + $this->lowerBound = $lowerBound; |
| 32 | + $this->upperBound = $upperBound; |
24 | 33 | } |
25 | 34 | |
26 | 35 | /** |
27 | 36 | * @see ParameterCriterion::validate |
28 | 37 | */ |
29 | 38 | public function validate( $value ) { |
| 39 | + if ( ! is_numeric( $value ) ) { |
| 40 | + return false; |
| 41 | + } |
30 | 42 | |
| 43 | + $value = (int)$value; |
| 44 | + |
| 45 | + return $value <= $this->upperBound && $value >= $this->lowerBound; |
31 | 46 | } |
32 | 47 | |
33 | 48 | } |
\ No newline at end of file |