1 | <?php |
||
51 | class HoneypotValidator extends AbstractValidator |
||
52 | { |
||
53 | /** |
||
54 | * Honeypot field names & structure |
||
55 | * |
||
56 | * @var array |
||
57 | */ |
||
58 | protected $honeypots; |
||
59 | /** |
||
60 | * Field renderer |
||
61 | * |
||
62 | * @var \Closure |
||
63 | */ |
||
64 | protected $renderer; |
||
65 | /** |
||
66 | * Validation order position |
||
67 | * |
||
68 | * @var int |
||
69 | */ |
||
70 | const POSITION = 50; |
||
71 | |||
72 | /** |
||
73 | * Constructor |
||
74 | * |
||
75 | * @param array $honeypots Honeypot field names & structure |
||
76 | * @param \Closure $renderer Field renderer |
||
77 | */ |
||
78 | 1 | public function __construct(array $honeypots, \Closure $renderer = null) |
|
83 | |||
84 | /** |
||
85 | * Validate a request |
||
86 | * |
||
87 | * @param ServerRequestInterface $request Request |
||
88 | * @param Antibot $antibot Antibot instance |
||
89 | * |
||
90 | * @return bool Success |
||
91 | * @throws HoneypotValidationException If a honeypot was triggered |
||
92 | */ |
||
93 | 1 | public function validate(ServerRequestInterface $request, Antibot $antibot): bool |
|
99 | |||
100 | /** |
||
101 | * Recursively validate honeypots |
||
102 | * |
||
103 | * @param array $honeypots Honeypot configuration |
||
104 | * @param array $data Submitted data |
||
105 | * @param Antibot $antibot Antibot instance |
||
106 | * @param null $prefix Variable prefix |
||
107 | * |
||
108 | * @return bool Success |
||
109 | * @throws HoneypotValidationException If a honeypot was triggered |
||
110 | */ |
||
111 | 1 | protected function validateHoneypotsRecursive(array $honeypots, array $data, Antibot $antibot, $prefix = null): bool |
|
138 | |||
139 | /** |
||
140 | * Create protective form HTML |
||
141 | * |
||
142 | * @param ServerRequestInterface $request Request |
||
143 | * @param Antibot $antibot Antibot instance |
||
144 | * |
||
145 | * @return InputElement[] HMTL input elements |
||
146 | */ |
||
147 | 1 | public function armor(ServerRequestInterface $request, Antibot $antibot): array |
|
154 | |||
155 | /** |
||
156 | * Recursively create honeypot input elements |
||
157 | * |
||
158 | * @param array $honeypots Honeypot configuration |
||
159 | * @param array $armor Armor input elements |
||
160 | * @param null $prefix Variable prefix |
||
161 | */ |
||
162 | 1 | protected function createHoneypotsRecursive(array $honeypots, array &$armor, $prefix = null): void |
|
180 | |||
181 | /** |
||
182 | * Return all serializable properties |
||
183 | * |
||
184 | * The renderer closure must be omitted in order to make the validator serializable |
||
185 | * |
||
186 | * @return array Serializable properties |
||
187 | */ |
||
188 | 1 | public function __sleep() |
|
192 | } |
||
193 |