1 | <?php |
||
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 | * Skipping validators |
||
87 | * |
||
88 | * @var string[] |
||
89 | */ |
||
90 | protected $skips = []; |
||
91 | /** |
||
92 | * Skipped |
||
93 | * |
||
94 | * @var bool |
||
95 | */ |
||
96 | protected $skipped = false; |
||
97 | |||
98 | /** |
||
99 | * Return whether the request was valid |
||
100 | * |
||
101 | * @return bool Valid |
||
102 | */ |
||
103 | 12 | public function isValid(): bool |
|
107 | |||
108 | /** |
||
109 | * Return whether the request was invalid |
||
110 | * |
||
111 | * @return bool Valid |
||
112 | */ |
||
113 | 10 | public function isFailed(): bool |
|
117 | |||
118 | /** |
||
119 | * Set whether the request was valid in general |
||
120 | * |
||
121 | * @param bool $valid Valid |
||
122 | */ |
||
123 | 7 | public function setValid(bool $valid): void |
|
127 | |||
128 | /** |
||
129 | * Return whether the request was whitelisted |
||
130 | * |
||
131 | * @return bool Whitelisted |
||
132 | */ |
||
133 | 3 | public function isWhitelisted(): bool |
|
137 | |||
138 | /** |
||
139 | * Add a named whitelist |
||
140 | * |
||
141 | * @param string $whitelist Whitelist |
||
142 | */ |
||
143 | 3 | public function addWhitelist(string $whitelist): void |
|
148 | |||
149 | /** |
||
150 | * Return all whitelists |
||
151 | * |
||
152 | * @return string[] Whitelist names |
||
153 | */ |
||
154 | 2 | public function getWhitelists(): array |
|
155 | { |
||
156 | 2 | return $this->whitelists; |
|
157 | } |
||
158 | |||
159 | /** |
||
160 | * Return whether the request was blacklisted |
||
161 | * |
||
162 | * @return bool Blacklisted |
||
163 | */ |
||
164 | 2 | public function isBlacklisted(): bool |
|
165 | { |
||
166 | 2 | return $this->blacklisted; |
|
167 | } |
||
168 | |||
169 | /** |
||
170 | * Add a named blacklist |
||
171 | * |
||
172 | * @param string $blacklist Blacklist |
||
173 | */ |
||
174 | 2 | public function addBlacklist(string $blacklist): void |
|
175 | { |
||
176 | 2 | $this->blacklists[] = $blacklist; |
|
177 | 2 | $this->blacklisted = true; |
|
178 | 2 | } |
|
179 | |||
180 | /** |
||
181 | * Return all blacklists |
||
182 | * |
||
183 | * @return string[] Blacklist names |
||
184 | */ |
||
185 | 2 | public function getBlacklists(): array |
|
186 | { |
||
187 | 2 | return $this->blacklists; |
|
188 | } |
||
189 | |||
190 | /** |
||
191 | * Add an error |
||
192 | * |
||
193 | * @param ErrorException $error |
||
194 | */ |
||
195 | 5 | public function addError(ErrorException $error): void |
|
199 | |||
200 | /** |
||
201 | * Return all errors |
||
202 | * |
||
203 | * @return ErrorException[] Errors |
||
204 | */ |
||
205 | 4 | public function getErrors(): array |
|
209 | |||
210 | /** |
||
211 | * Return whether this result has errors |
||
212 | * |
||
213 | * @return bool Has errors |
||
214 | */ |
||
215 | 6 | public function hasErrors(): bool |
|
219 | |||
220 | /** |
||
221 | * Add a skipping validator |
||
222 | * |
||
223 | * @param string $skip Skipping validator |
||
224 | */ |
||
225 | 4 | public function addSkip(string $skip): void |
|
230 | |||
231 | /** |
||
232 | * Return whether this result has skipping validators |
||
233 | * |
||
234 | * @return bool Has skipping validators |
||
235 | */ |
||
236 | 2 | public function hasSkips(): bool |
|
237 | { |
||
238 | 2 | return count($this->skips) > 0; |
|
239 | } |
||
240 | |||
241 | /** |
||
242 | * Return whether a validator skipped this validation |
||
243 | * |
||
244 | * @return bool Validation skipped |
||
245 | */ |
||
246 | 4 | public function isSkipped(): bool |
|
250 | } |
||
251 |