1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* antibot |
5
|
|
|
* |
6
|
|
|
* @category Jkphl |
7
|
|
|
* @package Jkphl\Antibot |
8
|
|
|
* @subpackage Jkphl\Antibot\Domain\Model |
9
|
|
|
* @author Joschi Kuphal <[email protected]> / @jkphl |
10
|
|
|
* @copyright Copyright © 2018 Joschi Kuphal <[email protected]> / @jkphl |
11
|
|
|
* @license http://opensource.org/licenses/MIT The MIT License (MIT) |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
/*********************************************************************************** |
15
|
|
|
* The MIT License (MIT) |
16
|
|
|
* |
17
|
|
|
* Copyright © 2018 Joschi Kuphal <[email protected]> |
18
|
|
|
* |
19
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of |
20
|
|
|
* this software and associated documentation files (the "Software"), to deal in |
21
|
|
|
* the Software without restriction, including without limitation the rights to |
22
|
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
23
|
|
|
* the Software, and to permit persons to whom the Software is furnished to do so, |
24
|
|
|
* subject to the following conditions: |
25
|
|
|
* |
26
|
|
|
* The above copyright notice and this permission notice shall be included in all |
27
|
|
|
* copies or substantial portions of the Software. |
28
|
|
|
* |
29
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
30
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
31
|
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
32
|
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
33
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
34
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
35
|
|
|
***********************************************************************************/ |
36
|
|
|
|
37
|
|
|
namespace Jkphl\Antibot\Domain\Model; |
38
|
|
|
|
39
|
|
|
use Jkphl\Antibot\Domain\Exceptions\ErrorException; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Validation Result |
43
|
|
|
* |
44
|
|
|
* @package Jkphl\Antibot |
45
|
|
|
* @subpackage Jkphl\Antibot\Domain\Model |
46
|
|
|
*/ |
47
|
|
|
class ValidationResult |
48
|
|
|
{ |
49
|
|
|
/** |
50
|
|
|
* Request was valid |
51
|
|
|
* |
52
|
|
|
* @var bool |
53
|
|
|
*/ |
54
|
|
|
protected $valid = true; |
55
|
|
|
/** |
56
|
|
|
* Whitelisted |
57
|
|
|
* |
58
|
|
|
* @var bool |
59
|
|
|
*/ |
60
|
|
|
protected $whitelisted = false; |
61
|
|
|
/** |
62
|
|
|
* Named whitelists |
63
|
|
|
* |
64
|
|
|
* @var string[] |
65
|
|
|
*/ |
66
|
|
|
protected $whitelists = []; |
67
|
|
|
/** |
68
|
|
|
* Blacklisted |
69
|
|
|
* |
70
|
|
|
* @var bool |
71
|
|
|
*/ |
72
|
|
|
protected $blacklisted = false; |
73
|
|
|
/** |
74
|
|
|
* Named blacklists |
75
|
|
|
* |
76
|
|
|
* @var string[] |
77
|
|
|
*/ |
78
|
|
|
protected $blacklists = []; |
79
|
|
|
/** |
80
|
|
|
* Error messages |
81
|
|
|
* |
82
|
|
|
* @var ErrorException[] |
83
|
|
|
*/ |
84
|
|
|
protected $errors = []; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Return whether the request was valid in general |
88
|
|
|
* |
89
|
|
|
* @return bool Valid |
90
|
|
|
*/ |
91
|
3 |
|
public function isValid(): bool |
92
|
|
|
{ |
93
|
3 |
|
return $this->valid; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Set whether the request was valid in general |
98
|
|
|
* |
99
|
|
|
* @param bool $valid Valid |
100
|
|
|
*/ |
101
|
1 |
|
public function setValid(bool $valid): void |
102
|
|
|
{ |
103
|
1 |
|
$this->valid = $valid; |
104
|
1 |
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Return whether the request was whitelisted |
108
|
|
|
* |
109
|
|
|
* @return bool Whitelisted |
110
|
|
|
*/ |
111
|
1 |
|
public function isWhitelisted(): bool |
112
|
|
|
{ |
113
|
1 |
|
return $this->whitelisted; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Add a named whitelist |
118
|
|
|
* |
119
|
|
|
* @param string $whitelist Whitelist |
120
|
|
|
*/ |
121
|
1 |
|
public function addWhitelist(string $whitelist): void |
122
|
|
|
{ |
123
|
1 |
|
$this->whitelists[] = $whitelist; |
124
|
1 |
|
$this->whitelisted = true; |
125
|
1 |
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Return all whitelists |
129
|
|
|
* |
130
|
|
|
* @return string[] Whitelist names |
131
|
|
|
*/ |
132
|
|
|
public function getWhitelists(): array |
133
|
|
|
{ |
134
|
|
|
return $this->whitelists; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Return whether the request was blacklisted |
139
|
|
|
* |
140
|
|
|
* @return bool Blacklisted |
141
|
|
|
*/ |
142
|
|
|
public function isBlacklisted(): bool |
143
|
|
|
{ |
144
|
|
|
return $this->blacklisted; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Add a named blacklist |
149
|
|
|
* |
150
|
|
|
* @param string $blacklist Blacklist |
151
|
|
|
*/ |
152
|
|
|
public function addBlacklist(string $blacklist): void |
153
|
|
|
{ |
154
|
|
|
$this->blacklists[] = $blacklist; |
155
|
|
|
$this->blacklisted = true; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* Return all blacklists |
160
|
|
|
* |
161
|
|
|
* @return string[] Blacklist names |
162
|
|
|
*/ |
163
|
|
|
public function getBlacklists(): array |
164
|
|
|
{ |
165
|
|
|
return $this->blacklists; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Add an error |
170
|
|
|
* |
171
|
|
|
* @param ErrorException $error |
172
|
|
|
*/ |
173
|
1 |
|
public function addError(ErrorException $error): void |
174
|
|
|
{ |
175
|
1 |
|
$this->errors[] = $error; |
176
|
1 |
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* Return all errors |
180
|
|
|
* |
181
|
|
|
* @return ErrorException[] Errors |
182
|
|
|
*/ |
183
|
1 |
|
public function getErrors(): array |
184
|
|
|
{ |
185
|
1 |
|
return $this->errors; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* Return whether this result has errors |
190
|
|
|
* |
191
|
|
|
* @return bool Has errors |
192
|
|
|
*/ |
193
|
1 |
|
public function hasErrors(): bool |
194
|
|
|
{ |
195
|
1 |
|
return count($this->errors) > 0; |
196
|
|
|
} |
197
|
|
|
} |
198
|
|
|
|