1 | <?php namespace Arcanedev\NoCaptcha\Utilities; |
||
11 | class ResponseV3 extends AbstractResponse implements ResponseContract |
||
12 | { |
||
13 | /* ----------------------------------------------------------------- |
||
14 | | Constants |
||
15 | | ----------------------------------------------------------------- |
||
16 | */ |
||
17 | |||
18 | /** |
||
19 | * Invalid JSON received |
||
20 | */ |
||
21 | const E_INVALID_JSON = 'invalid-json'; |
||
22 | |||
23 | /** |
||
24 | * Could not connect to service |
||
25 | */ |
||
26 | const E_CONNECTION_FAILED = 'connection-failed'; |
||
27 | |||
28 | /** |
||
29 | * Not a success, but no error codes received! |
||
30 | */ |
||
31 | const E_UNKNOWN_ERROR = 'unknown-error'; |
||
32 | |||
33 | /** |
||
34 | * Expected hostname did not match |
||
35 | */ |
||
36 | const E_HOSTNAME_MISMATCH = 'hostname-mismatch'; |
||
37 | |||
38 | /** |
||
39 | * Expected APK package name did not match |
||
40 | */ |
||
41 | const E_APK_PACKAGE_NAME_MISMATCH = 'apk_package_name-mismatch'; |
||
42 | |||
43 | /** |
||
44 | * Expected action did not match |
||
45 | */ |
||
46 | const E_ACTION_MISMATCH = 'action-mismatch'; |
||
47 | |||
48 | /** |
||
49 | * Score threshold not met |
||
50 | */ |
||
51 | const E_SCORE_THRESHOLD_NOT_MET = 'score-threshold-not-met'; |
||
52 | |||
53 | /** |
||
54 | * Challenge timeout |
||
55 | */ |
||
56 | const E_CHALLENGE_TIMEOUT = 'challenge-timeout'; |
||
57 | |||
58 | /* ----------------------------------------------------------------- |
||
59 | | Properties |
||
60 | | ----------------------------------------------------------------- |
||
61 | */ |
||
62 | |||
63 | /** |
||
64 | * Score assigned to the request |
||
65 | * |
||
66 | * @var float|null |
||
67 | */ |
||
68 | private $score; |
||
69 | |||
70 | /** |
||
71 | * Action as specified by the page |
||
72 | * |
||
73 | * @var string |
||
74 | */ |
||
75 | private $action; |
||
76 | |||
77 | /* ----------------------------------------------------------------- |
||
78 | | Constructor |
||
79 | | ----------------------------------------------------------------- |
||
80 | */ |
||
81 | |||
82 | /** |
||
83 | * Response constructor. |
||
84 | * |
||
85 | * @param bool $success |
||
86 | * @param array $errorCodes |
||
87 | * @param string|null $hostname |
||
88 | * @param string|null $challengeTs |
||
89 | * @param string|null $apkPackageName |
||
90 | * @param float|null $score |
||
91 | * @param string|null $action |
||
92 | */ |
||
93 | 60 | public function __construct($success, array $errorCodes = [], $hostname = null, $challengeTs = null, $apkPackageName = null, $score = null, $action = null) |
|
100 | |||
101 | /* ----------------------------------------------------------------- |
||
102 | | Getters |
||
103 | | ----------------------------------------------------------------- |
||
104 | */ |
||
105 | |||
106 | /** |
||
107 | * Get score |
||
108 | * |
||
109 | * @return float |
||
110 | */ |
||
111 | 16 | public function getScore() |
|
115 | |||
116 | /** |
||
117 | * Get action |
||
118 | * |
||
119 | * @return string |
||
120 | */ |
||
121 | 16 | public function getAction() |
|
125 | |||
126 | /* ----------------------------------------------------------------- |
||
127 | | Main Methods |
||
128 | | ----------------------------------------------------------------- |
||
129 | */ |
||
130 | |||
131 | /** |
||
132 | * Build the response from an array. |
||
133 | * |
||
134 | * @param array $array |
||
135 | * |
||
136 | * @return \Arcanedev\NoCaptcha\Utilities\ResponseV3 |
||
137 | */ |
||
138 | 44 | public static function fromArray(array $array) |
|
154 | |||
155 | /** |
||
156 | * Convert the response object to array. |
||
157 | * |
||
158 | * @return array |
||
159 | */ |
||
160 | 12 | public function toArray() |
|
172 | |||
173 | /* ----------------------------------------------------------------- |
||
174 | | Check Methods |
||
175 | | ----------------------------------------------------------------- |
||
176 | */ |
||
177 | |||
178 | /** |
||
179 | * Check the score. |
||
180 | * |
||
181 | * @param float $score |
||
182 | * |
||
183 | * @return bool |
||
184 | */ |
||
185 | 4 | public function isScore($score) |
|
189 | |||
190 | /** |
||
191 | * Check the action name. |
||
192 | * |
||
193 | * @param string $action |
||
194 | * |
||
195 | * @return bool |
||
196 | */ |
||
197 | 4 | public function isAction($action) |
|
201 | } |
||
202 |