1 | <?php |
||
21 | class GenericClient implements LoggerAwareInterface |
||
22 | { |
||
23 | use LoggerAwareTrait; |
||
24 | use ConfigurableTrait; |
||
25 | |||
26 | /* Statuses */ |
||
27 | const STATUS_OK = 'OK'; |
||
28 | const STATUS_CAPTCHA_NOT_READY = 'CAPCHA_NOT_READY'; |
||
29 | |||
30 | /** |
||
31 | * @var string |
||
32 | */ |
||
33 | protected $lastCaptchaId = ''; |
||
34 | |||
35 | /** |
||
36 | * @var string |
||
37 | */ |
||
38 | protected $serverBaseUri = ''; |
||
39 | |||
40 | /** |
||
41 | * @var bool |
||
42 | */ |
||
43 | protected $verbose = false; |
||
44 | |||
45 | /** |
||
46 | * @var string |
||
47 | */ |
||
48 | protected $apiKey = ''; |
||
49 | |||
50 | /** |
||
51 | * @var int |
||
52 | */ |
||
53 | protected $rTimeout = 5; |
||
54 | |||
55 | /** |
||
56 | * @var int |
||
57 | */ |
||
58 | protected $mTimeout = 120; |
||
59 | |||
60 | /** |
||
61 | * @var ClientInterface |
||
62 | */ |
||
63 | private $httpClient = null; |
||
64 | |||
65 | /** |
||
66 | * @param array $options |
||
67 | * @param string $apiKey |
||
68 | * @throws InvalidArgumentException |
||
69 | */ |
||
70 | 25 | public function __construct($apiKey, array $options = []) |
|
75 | |||
76 | /** |
||
77 | * @return string # Last successfully sent captcha task ID |
||
78 | */ |
||
79 | 2 | public function getLastCaptchaId() |
|
83 | |||
84 | /** |
||
85 | * @param ClientInterface $client |
||
86 | * @return $this |
||
87 | */ |
||
88 | 22 | public function setHttpClient(ClientInterface $client) |
|
94 | |||
95 | /** |
||
96 | * @param bool $verbose |
||
97 | * @return $this |
||
98 | */ |
||
99 | public function setVerbose($verbose) |
||
106 | |||
107 | /** |
||
108 | * @param string $path |
||
109 | * @param array $extra |
||
110 | * @return string |
||
111 | * @throws InvalidArgumentException |
||
112 | * @throws RuntimeException |
||
113 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
114 | */ |
||
115 | public function recognizeFile($path, array $extra = []) |
||
131 | |||
132 | /** |
||
133 | * @param string $content |
||
134 | * @param array $extra |
||
135 | * @return string |
||
136 | * @throws RuntimeException |
||
137 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
138 | */ |
||
139 | public function recognize($content, array $extra = []) |
||
164 | |||
165 | /** |
||
166 | * @param string $content # Captcha image content |
||
167 | * @param array $extra # Array of recognition options |
||
168 | * @return string # Captcha task ID |
||
169 | * @throws Throwable |
||
170 | */ |
||
171 | public function sendCaptcha($content, array $extra = []) |
||
199 | |||
200 | /** |
||
201 | * @param string $captchaId # Captcha task ID |
||
202 | * @return string|false # Solved captcha text or false if captcha is not ready |
||
203 | * @throws Throwable |
||
204 | */ |
||
205 | public function getCaptchaResult($captchaId) |
||
226 | |||
227 | /** |
||
228 | 19 | * @param string $responseText # Server response text usually begin with `ERROR_` prefix |
|
229 | * @return false|string # Error message text or false if associated message in not found |
||
230 | 19 | */ |
|
231 | 19 | protected function getErrorMessage($responseText) |
|
237 | |||
238 | 23 | /** |
|
239 | * @return ClientInterface |
||
240 | 23 | */ |
|
241 | 1 | protected function getHttpClient() |
|
250 | |||
251 | 15 | /** |
|
252 | * @return LoggerInterface |
||
253 | 15 | */ |
|
254 | 15 | public function getLogger() |
|
264 | } |
||
265 |