/
integer.php
49 lines (43 loc) · 952 Bytes
/
integer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
class DingesInteger extends DingesText {
protected $min;
protected $max;
function validate($value) {
if(($error = parent::validate($value)) !== true) {
return $error;
}
if(!ctype_digit($value)) {
return 'ERR_NON_INTEGER';
}
if($this->min !== NULL && $value < $this->min) {
return 'ERR_UNDER_MIN';
}
if($this->max !== NULL && $value > $this->max) {
return 'ERR_OVER_MAX';
}
return true;
}
function fillRestrictions() {
parent::fillRestrictions();
if($this->min !== NULL) {
$this->setRestriction('min', $this->min);
}
if($this->max !== NULL) {
$this->setRestriction('max', $this->max);
}
}
/* Simple getters and setters */
final function getMin() {
return $this->min;
}
final function setMin($value) {
$this->min = $value;
}
final function getMax() {
return $this->max;
}
final function setMax($value) {
$this->max = $value;
}
}
?>