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