1 | <?php |
||
15 | class FormTimestamp |
||
16 | { |
||
17 | use Utils\FormTrait; |
||
18 | use Utils\CryptTrait; |
||
19 | |||
20 | const KEY_GENERATOR = 'FORM_TIMESTAMP_GENERATOR'; |
||
21 | |||
22 | /** |
||
23 | * @var string The honeypot input name |
||
24 | */ |
||
25 | private $inputName = 'hpt_time'; |
||
26 | |||
27 | /** |
||
28 | * @var int Minimum seconds to determine whether the request is a bot |
||
29 | */ |
||
30 | private $min = 3; |
||
31 | |||
32 | /** |
||
33 | * @var int Max seconds to expire the form. Zero to do not expire |
||
34 | */ |
||
35 | private $max = 0; |
||
36 | |||
37 | /** |
||
38 | * Returns a callable to generate the inputs. |
||
39 | * |
||
40 | * @param ServerRequestInterface $request |
||
41 | * |
||
42 | * @return callable|null |
||
43 | */ |
||
44 | public static function getGenerator(ServerRequestInterface $request) |
||
48 | |||
49 | /** |
||
50 | * Set the field name. |
||
51 | * |
||
52 | * @param string $inputName |
||
53 | * |
||
54 | * @return self |
||
55 | */ |
||
56 | public function inputName($inputName) |
||
62 | |||
63 | /** |
||
64 | * Minimum time required. |
||
65 | * |
||
66 | * @param int $seconds |
||
67 | * |
||
68 | * @return self |
||
69 | */ |
||
70 | public function min($seconds) |
||
76 | |||
77 | /** |
||
78 | * Max time before expire the form. |
||
79 | * |
||
80 | * @param int $seconds |
||
81 | * |
||
82 | * @return self |
||
83 | */ |
||
84 | public function max($seconds) |
||
90 | |||
91 | /** |
||
92 | * Execute the middleware. |
||
93 | * |
||
94 | * @param ServerRequestInterface $request |
||
95 | * @param ResponseInterface $response |
||
96 | * @param callable $next |
||
97 | * |
||
98 | * @return ResponseInterface |
||
99 | */ |
||
100 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) |
||
126 | |||
127 | /** |
||
128 | * Check whether the request is valid. |
||
129 | * |
||
130 | * @param ServerRequestInterface $request |
||
131 | * |
||
132 | * @return bool |
||
133 | */ |
||
134 | private function isValid(ServerRequestInterface $request) |
||
175 | } |
||
176 |