-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSettingCaptchaQuestions.php
More file actions
57 lines (49 loc) · 1.4 KB
/
SettingCaptchaQuestions.php
File metadata and controls
57 lines (49 loc) · 1.4 KB
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
50
51
52
53
54
55
56
57
<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
class SettingCaptchaQuestions implements Rule {
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value) {
$value = json_decode($value, true);
if ($value === null) {
return false;
}
foreach (array_keys($value) as $question) {
if (!is_string($question)) {
return false;
}
if (strlen($question) > 200) {
return false;
}
}
foreach (array_values($value) as $answers) {
if (!is_array($answers)) {
return false;
}
if (count((array) $answers) === 0) {
return false;
}
foreach ($answers as $answer) {
if (!is_string($answer)) {
return false;
}
if (strlen($answer) > 200) {
return false;
}
}
}
return true;
}
/**
* Get the validation error message.
*/
public function message(): string {
return 'Value must be JSON mapping of questions to an array of answers and neither question nor answers may be longer than 200 chars';
}
}