/**
* Выполнить запрос
*
* @param mixed $ch
*/
public function exec($ch = null)
{
if ($this->headers) {
$headers = array_filter($this->headers, 'strlen');
$this->setOpt(CURLOPT_HTTPHEADER, array_map(function ($value, $key) {
return $key . ': ' . $value;
}, $headers, array_keys($headers)));
}
$response = parent::exec($ch);
// TODO совместимость с другими API
if ($this->http_status_code && isset($this->exceptions[$this->http_status_code])) {
$response['error'] = true;
$response['message'] = implode('; ', $this->response);
}
if (isset($response['error'])) {
$exception = 'Exception';
if (isset($this->exceptions[$this->error_code])) {
$exception = 'Mackey\\Yandex\\Exception\\' . $this->exceptions[$this->error_code];
}
try {
throw (new \ReflectionClass($exception))->newInstance($response['message'], $this->error_code);
} catch (\ReflectionException $exc) {
throw new \Exception($response['message'], $this->error_code, $exc);
}
}
return $response;
}