1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* PayPal Donation extension for the phpBB Forum Software package. |
5
|
|
|
* |
6
|
|
|
* @copyright (c) 2015-2024 Skouat |
7
|
|
|
* @license GNU General Public License, version 2 (GPL-2.0) |
8
|
|
|
* |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace skouat\ppde\helpers; |
12
|
|
|
|
13
|
|
|
class compare_helper |
14
|
|
|
{ |
15
|
|
|
/** @var array */ |
16
|
|
|
private static $operators_table = [ |
17
|
|
|
'<' => 'compare_lt', |
18
|
|
|
'<=' => 'compare_lte', |
19
|
|
|
'==' => 'compare_eq', |
20
|
|
|
'===' => 'compare_id', |
21
|
|
|
'>=' => 'compare_gte', |
22
|
|
|
'>' => 'compare_gt', |
23
|
|
|
'<>' => 'compare_diff', |
24
|
|
|
'!=' => 'compare_not_eq', |
25
|
|
|
'!==' => 'compare_not_id', |
26
|
|
|
]; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Compare two values |
30
|
|
|
* |
31
|
|
|
* @param int $value1 |
32
|
|
|
* @param int $value2 |
33
|
|
|
* @param string $operator |
34
|
|
|
* |
35
|
|
|
* @return bool |
36
|
|
|
* @access public |
37
|
|
|
*/ |
38
|
|
|
public function compare_value($value1, $value2, $operator): bool |
39
|
|
|
{ |
40
|
|
|
if (!array_key_exists($operator, self::$operators_table)) |
41
|
|
|
{ |
42
|
|
|
return false; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
$method = self::$operators_table[$operator]; |
46
|
|
|
return $this->$method($value1, $value2); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Methods are called by $this->compare_value |
51
|
|
|
* |
52
|
|
|
* @param mixed $a The first value to compare. |
53
|
|
|
* @param mixed $b The second value to compare. |
54
|
|
|
* |
55
|
|
|
* @return bool |
56
|
|
|
* @access private |
57
|
|
|
*/ |
58
|
|
|
private function compare_lt($a, $b) |
59
|
|
|
{ |
60
|
|
|
return $a < $b; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
private function compare_lte($a, $b) |
64
|
|
|
{ |
65
|
|
|
return $a <= $b; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
private function compare_eq($a, $b) |
69
|
|
|
{ |
70
|
|
|
return $a == $b; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
private function compare_id($a, $b) |
74
|
|
|
{ |
75
|
|
|
return $a === $b; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
private function compare_gte($a, $b) |
79
|
|
|
{ |
80
|
|
|
return $a >= $b; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
private function compare_gt($a, $b) |
84
|
|
|
{ |
85
|
|
|
return $a > $b; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
private function compare_diff($a, $b) |
89
|
|
|
{ |
90
|
|
|
return $a <> $b; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
private function compare_not_eq($a, $b) |
94
|
|
|
{ |
95
|
|
|
return $a != $b; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
private function compare_not_id($a, $b) |
99
|
|
|
{ |
100
|
|
|
return $a !== $b; |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|