|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace GinoPane\PHPolyglot\API\Implementation\SpellCheck; |
|
4
|
|
|
|
|
5
|
|
|
use GinoPane\NanoRest\Request\RequestContext; |
|
6
|
|
|
use GinoPane\NanoRest\Exceptions\TransportException; |
|
7
|
|
|
use GinoPane\NanoRest\Response\ResponseContextAbstract; |
|
8
|
|
|
use GinoPane\PHPolyglot\API\Implementation\ApiAbstract; |
|
9
|
|
|
use GinoPane\PHPolyglot\Supplemental\Language\Language; |
|
10
|
|
|
use GinoPane\NanoRest\Exceptions\ResponseContextException; |
|
11
|
|
|
use GinoPane\PHPolyglot\Exception\BadResponseContextException; |
|
12
|
|
|
use GinoPane\PHPolyglot\Exception\MethodDoesNotExistException; |
|
13
|
|
|
use GinoPane\PHPolyglot\API\Response\SpellCheck\SpellCheckResponse; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Interface SpellCheckApiAbstract |
|
17
|
|
|
* |
|
18
|
|
|
* @author Sergey <Gino Pane> Karavay |
|
19
|
|
|
*/ |
|
20
|
|
|
abstract class SpellCheckApiAbstract extends ApiAbstract implements SpellCheckApiInterface |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* Check spelling for multiple text strings |
|
24
|
|
|
* |
|
25
|
|
|
* @param array $texts |
|
26
|
|
|
* @param Language $languageFrom |
|
27
|
|
|
* |
|
28
|
|
|
* @throws TransportException |
|
29
|
|
|
* @throws ResponseContextException |
|
30
|
|
|
* @throws BadResponseContextException |
|
31
|
|
|
* @throws MethodDoesNotExistException |
|
32
|
|
|
* |
|
33
|
|
|
* @return SpellCheckResponse |
|
34
|
|
|
*/ |
|
35
|
|
|
public function checkTexts(array $texts, Language $languageFrom): SpellCheckResponse |
|
36
|
|
|
{ |
|
37
|
|
|
/** @var SpellCheckResponse $response */ |
|
38
|
|
|
$response = $this->callApi(__FUNCTION__, func_get_args()); |
|
39
|
|
|
|
|
40
|
|
|
return $response; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Create request context for spell-check request |
|
45
|
|
|
* |
|
46
|
|
|
* @param array $texts |
|
47
|
|
|
* @param Language $languageFrom |
|
48
|
|
|
* |
|
49
|
|
|
* @return RequestContext |
|
50
|
|
|
*/ |
|
51
|
|
|
abstract protected function createCheckTextsContext( |
|
52
|
|
|
array $texts, |
|
53
|
|
|
Language $languageFrom |
|
54
|
|
|
): RequestContext; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Process response of spell-check request and prepare valid response |
|
58
|
|
|
* |
|
59
|
|
|
* @param ResponseContextAbstract $context |
|
60
|
|
|
* |
|
61
|
|
|
* @return SpellCheckResponse |
|
62
|
|
|
*/ |
|
63
|
|
|
abstract protected function prepareCheckTextsResponse(ResponseContextAbstract $context): SpellCheckResponse; |
|
64
|
|
|
} |
|
65
|
|
|
|