1 | <?php |
||
20 | class GenericClient implements LoggerAwareInterface |
||
21 | { |
||
22 | use LoggerAwareTrait; |
||
23 | use ConfigurableTrait; |
||
24 | |||
25 | /* Statuses */ |
||
26 | const STATUS_OK = 'OK'; |
||
27 | const STATUS_CAPTCHA_NOT_READY = 'CAPCHA_NOT_READY'; |
||
28 | |||
29 | /** |
||
30 | * @var string |
||
31 | */ |
||
32 | protected $lastCaptchaId = ''; |
||
33 | |||
34 | /** |
||
35 | * @var string |
||
36 | */ |
||
37 | protected $serverBaseUri = ''; |
||
38 | |||
39 | /** |
||
40 | * @var bool |
||
41 | */ |
||
42 | protected $verbose = false; |
||
43 | |||
44 | /** |
||
45 | * @var string |
||
46 | */ |
||
47 | protected $apiKey = ''; |
||
48 | |||
49 | /** |
||
50 | * @var int |
||
51 | */ |
||
52 | protected $rTimeout = 5; |
||
53 | |||
54 | /** |
||
55 | * @var int |
||
56 | */ |
||
57 | protected $mTimeout = 120; |
||
58 | |||
59 | /** |
||
60 | * @var ClientInterface |
||
61 | */ |
||
62 | private $httpClient = null; |
||
63 | |||
64 | /** |
||
65 | * @param array $options |
||
66 | * @param string $apiKey |
||
67 | */ |
||
68 | 25 | public function __construct($apiKey, array $options = []) |
|
73 | |||
74 | /** |
||
75 | * @return string # Last successfully sent captcha task ID |
||
76 | */ |
||
77 | 2 | public function getLastCaptchaId() |
|
81 | |||
82 | /** |
||
83 | * @param ClientInterface $client |
||
84 | * @return $this |
||
85 | */ |
||
86 | 22 | public function setHttpClient(ClientInterface $client) |
|
92 | |||
93 | /** |
||
94 | * @param string $path |
||
95 | * @param array $extra |
||
96 | * @return string |
||
97 | * @throws RucaptchaException |
||
98 | */ |
||
99 | public function recognizeFile($path, array $extra = []) |
||
115 | |||
116 | /** |
||
117 | * @param string $content |
||
118 | * @param array $extra |
||
119 | * @return string |
||
120 | * @throws RuntimeException |
||
121 | */ |
||
122 | public function recognize($content, array $extra = []) |
||
150 | |||
151 | /** |
||
152 | * @param string $content # Captcha image content |
||
153 | * @param array $extra # Array of recognition options |
||
154 | * @return string # Captcha task ID |
||
155 | * @throws RuntimeException |
||
156 | */ |
||
157 | 13 | public function sendCaptcha($content, array $extra = []) |
|
182 | |||
183 | /** |
||
184 | * @param string $captchaId # Captcha task ID |
||
185 | * @return string|false # Solved captcha text or false if captcha is not ready |
||
186 | * @throws RuntimeException |
||
187 | */ |
||
188 | 9 | public function getCaptchaResult($captchaId) |
|
205 | |||
206 | /** |
||
207 | * @param string $responseText # Server response text usually begin with `ERROR_` prefix |
||
208 | * @return false|string # Error message text or false if associated message in not found |
||
209 | */ |
||
210 | 19 | protected function getErrorMessage($responseText) |
|
216 | |||
217 | /** |
||
218 | * @return ClientInterface |
||
219 | */ |
||
220 | 23 | protected function getHttpClient() |
|
229 | |||
230 | /** |
||
231 | * @return LoggerInterface |
||
232 | */ |
||
233 | 15 | protected function getLogger() |
|
244 | } |