1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Hryvinskyi\InvisibleCaptcha\Model\ReCaptcha; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class RequestParameters |
9
|
|
|
*/ |
10
|
|
|
class RequestParameters |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* The shared key between your site and reCAPTCHA. |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
private $secret; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* The user response token provided by reCAPTCHA, verifying the user on your site. |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
private $response; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Remote user's IP address. |
26
|
|
|
* @var string|null |
27
|
|
|
*/ |
28
|
|
|
private $remoteIp = null; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Client version. |
32
|
|
|
* @var string|null |
33
|
|
|
*/ |
34
|
|
|
private $version = null; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @return string |
38
|
|
|
*/ |
39
|
|
|
public function getSecret(): string |
40
|
|
|
{ |
41
|
|
|
return $this->secret; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param string $secret |
46
|
|
|
* |
47
|
|
|
* @return RequestParameters |
48
|
|
|
*/ |
49
|
|
|
public function setSecret(string $secret): RequestParameters |
50
|
|
|
{ |
51
|
|
|
$this->secret = $secret; |
52
|
|
|
|
53
|
|
|
return $this; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return string |
58
|
|
|
*/ |
59
|
|
|
public function getResponse(): string |
60
|
|
|
{ |
61
|
|
|
return $this->response; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param string $response |
66
|
|
|
* |
67
|
|
|
* @return RequestParameters |
68
|
|
|
*/ |
69
|
|
|
public function setResponse(string $response): RequestParameters |
70
|
|
|
{ |
71
|
|
|
$this->response = $response; |
72
|
|
|
|
73
|
|
|
return $this; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return string |
78
|
|
|
*/ |
79
|
|
|
public function getRemoteIp(): ?string |
80
|
|
|
{ |
81
|
|
|
return $this->remoteIp; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param string|bool $remoteIp |
86
|
|
|
* |
87
|
|
|
* @return RequestParameters |
88
|
|
|
*/ |
89
|
|
|
public function setRemoteIp(?string $remoteIp): RequestParameters |
90
|
|
|
{ |
91
|
|
|
$this->remoteIp = $remoteIp; |
92
|
|
|
|
93
|
|
|
return $this; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @return string |
98
|
|
|
*/ |
99
|
|
|
public function getVersion(): ?string |
100
|
|
|
{ |
101
|
|
|
return $this->version; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @param string $version |
106
|
|
|
* |
107
|
|
|
* @return RequestParameters |
108
|
|
|
*/ |
109
|
|
|
public function setVersion(string $version): RequestParameters |
110
|
|
|
{ |
111
|
|
|
$this->version = $version; |
112
|
|
|
|
113
|
|
|
return $this; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Array representation. |
118
|
|
|
* |
119
|
|
|
* @return array Array formatted parameters. |
120
|
|
|
*/ |
121
|
|
|
public function toArray(): array |
122
|
|
|
{ |
123
|
|
|
$params = [ |
124
|
|
|
'secret' => $this->getSecret(), |
125
|
|
|
'response' => $this->getResponse(), |
126
|
|
|
'remoteip' => $this->getRemoteIp(), |
127
|
|
|
'version' => $this->getVersion() |
128
|
|
|
]; |
129
|
|
|
|
130
|
|
|
return array_filter($params); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Query string representation for HTTP request. |
135
|
|
|
* |
136
|
|
|
* @return string Query string formatted parameters. |
137
|
|
|
*/ |
138
|
|
|
public function toQueryString(): string |
139
|
|
|
{ |
140
|
|
|
return http_build_query($this->toArray(), '', '&'); |
141
|
|
|
} |
142
|
|
|
} |