|
1
|
|
|
<?php |
|
2
|
|
|
namespace AlgoWeb\xsdTypes\Facets; |
|
3
|
|
|
|
|
4
|
|
|
trait MinMaxTrait |
|
5
|
|
|
{ |
|
6
|
|
|
/** |
|
7
|
|
|
* @Exclude |
|
8
|
|
|
* @var int|float|\DateTime|\DateInterval Specifies the lower bounds for numeric values (the value must be greater |
|
9
|
|
|
* than or equal to this value) |
|
10
|
|
|
*/ |
|
11
|
|
|
private $minInclusive = null; |
|
12
|
|
|
/** |
|
13
|
|
|
* @Exclude |
|
14
|
|
|
* @var int|float|\DateTime|\DateInterval Specifies the upper bounds for numeric values (the value must be less |
|
15
|
|
|
* than or equal to this value) |
|
16
|
|
|
*/ |
|
17
|
|
|
private $maxInclusive = null; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @param int|float|\DateTime|\DateInterval $v Specifies the upper bounds for numeric values (the value must be |
|
21
|
|
|
* less than this value) |
|
22
|
|
|
*/ |
|
23
|
|
View Code Duplication |
public function setMaxExclusive($v) |
|
24
|
|
|
{ |
|
25
|
|
|
if (is_int($v)) { |
|
26
|
|
|
$this->maxInclusive = $v - 1; |
|
27
|
|
|
} else { |
|
28
|
|
|
$this->minInclusive = $v - 0.000001; |
|
29
|
|
|
} |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param int|float|\DateTime|\DateInterval $v Specifies the upper bounds for numeric values |
|
34
|
|
|
* (the value must be less than or equal to this value) |
|
35
|
|
|
*/ |
|
36
|
|
|
public function setMaxInclusive($v) |
|
37
|
|
|
{ |
|
38
|
|
|
$this->maxInclusive = $v; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param int|float|\DateTime|\DateInterval $v Specifies the lower bounds for numeric values |
|
43
|
|
|
* (the value must be greater than this value) |
|
44
|
|
|
*/ |
|
45
|
|
View Code Duplication |
public function setMinExclusive($v) |
|
46
|
|
|
{ |
|
47
|
|
|
if (is_int($v)) { |
|
48
|
|
|
$this->minInclusive = $v + 1; |
|
49
|
|
|
} else { |
|
50
|
|
|
$this->minInclusive = $v + 0.000001; |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param int|float|\DateTime|\DateInterval $v Specifies the lower bounds for numeric values |
|
56
|
|
|
* (the value must be greater than or equal to this value) |
|
57
|
|
|
*/ |
|
58
|
|
|
public function setMinInclusive($v) |
|
59
|
|
|
{ |
|
60
|
|
|
$this->minInclusive = $v; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function checkMinMax($v) |
|
64
|
|
|
{ |
|
65
|
|
|
if (null != $this->minInclusive) { |
|
66
|
|
|
$this->checkMin($v); |
|
67
|
|
|
} |
|
68
|
|
|
if (null != $this->maxInclusive) { |
|
69
|
|
|
$this->checkMax($v); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
private function checkMin($v) |
|
74
|
|
|
{ |
|
75
|
|
|
if ($v < $this->minInclusive) { |
|
76
|
|
|
throw new \InvalidArgumentException('Value less than allowed min value ' . __CLASS__); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
private function checkMax($v) |
|
81
|
|
|
{ |
|
82
|
|
|
if ($v > $this->maxInclusive) { |
|
83
|
|
|
throw new \InvalidArgumentException('Value greater than allowed max value ' . __CLASS__); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|