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 | */ |
||
69 | 25 | public function __construct($apiKey, array $options = []) |
|
74 | |||
75 | /** |
||
76 | * @return string # Last successfully sent captcha task ID |
||
77 | */ |
||
78 | 2 | public function getLastCaptchaId() |
|
82 | |||
83 | /** |
||
84 | * @param ClientInterface $client |
||
85 | * @return $this |
||
86 | */ |
||
87 | 22 | public function setHttpClient(ClientInterface $client) |
|
93 | |||
94 | /** |
||
95 | * @param bool $verbose |
||
96 | * @return $this |
||
97 | */ |
||
98 | public function setVerbose($verbose) |
||
105 | |||
106 | /** |
||
107 | * @param string $path |
||
108 | * @param array $extra |
||
109 | * @return string |
||
110 | * @throws Exception |
||
111 | */ |
||
112 | public function recognizeFile($path, array $extra = []) |
||
128 | |||
129 | /** |
||
130 | * @param string $content |
||
131 | * @param array $extra |
||
132 | * @return string |
||
133 | * @throws RuntimeException |
||
134 | */ |
||
135 | public function recognize($content, array $extra = []) |
||
162 | |||
163 | /** |
||
164 | * @param string $content # Captcha image content |
||
165 | * @param array $extra # Array of recognition options |
||
166 | * @return string # Captcha task ID |
||
167 | * @throws RuntimeException |
||
168 | */ |
||
169 | 13 | public function sendCaptcha($content, array $extra = []) |
|
194 | |||
195 | /** |
||
196 | * @param string $captchaId # Captcha task ID |
||
197 | * @return string|false # Solved captcha text or false if captcha is not ready |
||
198 | * @throws RuntimeException |
||
199 | */ |
||
200 | 9 | public function getCaptchaResult($captchaId) |
|
217 | |||
218 | /** |
||
219 | * @param string $responseText # Server response text usually begin with `ERROR_` prefix |
||
220 | * @return false|string # Error message text or false if associated message in not found |
||
221 | */ |
||
222 | 19 | protected function getErrorMessage($responseText) |
|
228 | |||
229 | /** |
||
230 | * @return ClientInterface |
||
231 | */ |
||
232 | 23 | protected function getHttpClient() |
|
241 | |||
242 | /** |
||
243 | * @return LoggerInterface |
||
244 | */ |
||
245 | 15 | public function getLogger() |
|
255 | } |
||
256 |