private function getResponse($data)
{
if (!is_string($data) && !is_array($data)) {
throw new InvalidArgumentException('Invalid argument provided');
}
$tokenData = is_array($data) ? implode('', $data) : $data;
$queryArray = array_merge($this->urlParams, ['sl' => $this->sourceLanguage, 'tl' => $this->targetLanguage, 'tk' => $this->tokenProvider->generateToken($this->sourceLanguage, $this->targetLanguage, $tokenData)]);
$queryUrl = preg_replace('/%5B(?:[0-9]|[1-9][0-9]+)%5D=/', '=', http_build_query($queryArray));
$queryBodyArray = ['q' => $data];
$queryBodyEncoded = preg_replace('/%5B(?:[0-9]|[1-9][0-9]+)%5D=/', '=', http_build_query($queryBodyArray));
try {
$response = $this->httpClient->post($this->urlBase, ['query' => $queryUrl, 'body' => $queryBodyEncoded] + $this->httpOptions);
} catch (GuzzleRequestException $e) {
throw new ErrorException($e->getMessage());
}
$body = $response->getBody();
// Get response body
// Modify body to avoid json errors
$bodyJson = preg_replace(array_keys($this->resultRegexes), array_values($this->resultRegexes), $body);
// Decode JSON data
if (($bodyArray = json_decode($bodyJson, true)) === null) {
throw new UnexpectedValueException('Data cannot be decoded or it\'s deeper than the recursion limit');
}
return $bodyArray;
}