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 = []) |
||
160 | |||
161 | /** |
||
162 | * @param string $content # Captcha image content |
||
163 | * @param array $extra # Array of recognition options |
||
164 | * @return string # Captcha task ID |
||
165 | * @throws RuntimeException |
||
166 | */ |
||
167 | 13 | public function sendCaptcha($content, array $extra = []) |
|
189 | |||
190 | /** |
||
191 | * @param string $captchaId # Captcha task ID |
||
192 | * @return string|false # Solved captcha text or false if captcha is not ready |
||
193 | * @throws RuntimeException |
||
194 | */ |
||
195 | 9 | public function getCaptchaResult($captchaId) |
|
211 | |||
212 | /** |
||
213 | * @param string $responseText # Server response text usually begin with `ERROR_` prefix |
||
214 | * @return false|string # Error message text or false if associated message in not found |
||
215 | */ |
||
216 | 19 | protected function getErrorMessage($responseText) |
|
222 | |||
223 | /** |
||
224 | * @return ClientInterface |
||
225 | */ |
||
226 | 23 | protected function getHttpClient() |
|
235 | |||
236 | /** |
||
237 | * @return LoggerInterface |
||
238 | */ |
||
239 | 1 | protected function getLogger() |
|
250 | } |