1 | <?php |
||
58 | class Antibot implements LoggerAwareInterface |
||
59 | { |
||
60 | /** |
||
61 | * Session persistent, unique token |
||
62 | * |
||
63 | * @var string |
||
64 | */ |
||
65 | protected $unique; |
||
66 | /** |
||
67 | * Antibot prefix |
||
68 | * |
||
69 | * @var string |
||
70 | */ |
||
71 | protected $prefix; |
||
72 | /** |
||
73 | * Unique signature |
||
74 | * |
||
75 | * @var string |
||
76 | */ |
||
77 | protected $signature; |
||
78 | /** |
||
79 | * Parameter prefix |
||
80 | * |
||
81 | * @var string |
||
82 | */ |
||
83 | protected $parameterPrefix; |
||
84 | /** |
||
85 | * GET & POST data |
||
86 | * |
||
87 | * @var null|array |
||
88 | */ |
||
89 | protected $data = null; |
||
90 | /** |
||
91 | * Validators |
||
92 | * |
||
93 | * @var ValidatorInterface[] |
||
94 | */ |
||
95 | protected $validators = []; |
||
96 | /** |
||
97 | * Immutable instance |
||
98 | * |
||
99 | * @var bool |
||
100 | */ |
||
101 | protected $immutable = false; |
||
102 | /** |
||
103 | * Logger |
||
104 | * |
||
105 | * @var LoggerInterface |
||
106 | */ |
||
107 | protected $logger = null; |
||
108 | /** |
||
109 | * Default antibot prefix |
||
110 | * |
||
111 | * @var string |
||
112 | */ |
||
113 | const DEFAULT_PREFIX = 'antibot'; |
||
114 | |||
115 | /** |
||
116 | * Antibot constructor |
||
117 | * |
||
118 | * @param string $unique Session-persistent, unique key |
||
119 | * @param string $prefix Prefix |
||
120 | */ |
||
121 | 10 | public function __construct(string $unique, string $prefix = self::DEFAULT_PREFIX) |
|
127 | |||
128 | /** |
||
129 | * Return the session persistent, unique token |
||
130 | * |
||
131 | * @return string Session persistent, unique token |
||
132 | */ |
||
133 | 4 | public function getUnique(): string |
|
137 | |||
138 | /** |
||
139 | * Return the prefix |
||
140 | * |
||
141 | * @return string Prefix |
||
142 | */ |
||
143 | 1 | public function getPrefix(): string |
|
147 | |||
148 | /** |
||
149 | * Return the submitted Antibot data |
||
150 | * |
||
151 | * @return string[] Antibot data |
||
152 | */ |
||
153 | 4 | public function getData(): ?array |
|
159 | |||
160 | /** |
||
161 | * Return the parameter prefix |
||
162 | * |
||
163 | * @return string Parameter prefix |
||
164 | * @throws RuntimeException If Antibot needs to be initialized |
||
165 | */ |
||
166 | 4 | public function getParameterPrefix(): string |
|
172 | |||
173 | /** |
||
174 | * Validate a request |
||
175 | * |
||
176 | * @param ServerRequestInterface $request Request |
||
177 | * |
||
178 | * @return ValidationResult Validation result |
||
179 | */ |
||
180 | 4 | public function validate(ServerRequestInterface $request): ValidationResult |
|
219 | |||
220 | /** |
||
221 | * Create and return the raw armor input elements |
||
222 | * |
||
223 | * @param ServerRequestInterface $request Request |
||
224 | * |
||
225 | * @return InputElement[] Armor input elements |
||
226 | */ |
||
227 | 4 | public function armorInputs(ServerRequestInterface $request): array |
|
243 | |||
244 | /** |
||
245 | * Compare and sort validators |
||
246 | * |
||
247 | * @param ValidatorInterface $validator1 Validator 1 |
||
248 | * @param ValidatorInterface $validator2 Validator 2 |
||
249 | * |
||
250 | * @return int Sorting |
||
251 | */ |
||
252 | protected function sortValidators(ValidatorInterface $validator1, ValidatorInterface $validator2): int |
||
262 | |||
263 | /** |
||
264 | * Pre-validation initialization |
||
265 | * |
||
266 | * @param ServerRequestInterface $request Request |
||
267 | */ |
||
268 | 5 | protected function initialize(ServerRequestInterface $request): void |
|
276 | |||
277 | /** |
||
278 | * Calculate the unique signature |
||
279 | * |
||
280 | * @return string Signature |
||
281 | */ |
||
282 | 5 | protected function calculateSignature(): string |
|
288 | |||
289 | /** |
||
290 | * Extract the antibot data from GET and POST parameters |
||
291 | * |
||
292 | * @param ServerRequestInterface $request Request |
||
293 | */ |
||
294 | 5 | protected function extractData(ServerRequestInterface $request): void |
|
302 | |||
303 | /** |
||
304 | * Check whether this Antibot instance is immutable |
||
305 | * |
||
306 | * @throws RuntimeException If the Antibot instance is immutable |
||
307 | */ |
||
308 | 5 | protected function checkImmutable(): void |
|
317 | |||
318 | /** |
||
319 | * Check whether this Antibot instance is already initialized |
||
320 | * |
||
321 | * @throws RuntimeException If the Antibot instance still needs to be initialized |
||
322 | */ |
||
323 | 4 | protected function checkInitialized(): void |
|
333 | |||
334 | /** |
||
335 | * Return the logger |
||
336 | * |
||
337 | * @return LoggerInterface Logger |
||
338 | */ |
||
339 | 4 | public function getLogger(): LoggerInterface |
|
343 | |||
344 | /** |
||
345 | * Sets a logger instance on the object |
||
346 | * |
||
347 | * @param LoggerInterface $logger Logger |
||
348 | * |
||
349 | * @return void |
||
350 | */ |
||
351 | 10 | public function setLogger(LoggerInterface $logger): void |
|
355 | } |
||
356 |