2016-01-13 18:43:41 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class RequestProxy
|
|
|
|
* @package RetailCrm\Component
|
|
|
|
*/
|
|
|
|
class RetailcrmProxy
|
|
|
|
{
|
|
|
|
private $api;
|
|
|
|
private $log;
|
|
|
|
|
2017-08-14 12:06:10 +02:00
|
|
|
public function __construct($url, $key, $log, $version = '4')
|
|
|
|
{
|
|
|
|
switch ($version) {
|
|
|
|
case '5':
|
|
|
|
$this->api = new RetailcrmApiClientV5($url, $key);
|
|
|
|
break;
|
|
|
|
case '4':
|
|
|
|
$this->api = new RetailcrmApiClientV4($url, $key);
|
|
|
|
break;
|
|
|
|
case '3':
|
|
|
|
$this->api = new RetailcrmApiClientV3($url, $key);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-01-13 18:43:41 +03:00
|
|
|
$this->log = $log;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function __call($method, $arguments)
|
2017-08-14 12:06:10 +02:00
|
|
|
{
|
|
|
|
$date = date('Y-m-d H:i:s');
|
2016-01-13 18:43:41 +03:00
|
|
|
try {
|
|
|
|
$response = call_user_func_array(array($this->api, $method), $arguments);
|
|
|
|
|
|
|
|
if (!$response->isSuccessful()) {
|
2017-08-14 12:06:10 +02:00
|
|
|
error_log("[$date] @ [$method] " . $response->getErrorMsg() . "\n", 3, $this->log);
|
2016-01-13 18:43:41 +03:00
|
|
|
if (isset($response['errors'])) {
|
2019-05-28 11:37:29 +03:00
|
|
|
RetailcrmApiErrors::set($response['errors'], $response->getStatusCode());
|
2016-01-13 18:43:41 +03:00
|
|
|
$error = implode("\n", $response['errors']);
|
|
|
|
error_log($error . "\n", 3, $this->log);
|
|
|
|
}
|
|
|
|
$response = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
} catch (CurlException $e) {
|
2017-08-14 12:06:10 +02:00
|
|
|
error_log("[$date] @ [$method] " . $e->getMessage() . "\n", 3, $this->log);
|
2016-01-13 18:43:41 +03:00
|
|
|
return false;
|
|
|
|
} catch (InvalidJsonException $e) {
|
2017-08-14 12:06:10 +02:00
|
|
|
error_log("[$date] @ [$method] " . $e->getMessage() . "\n", 3, $this->log);
|
2016-01-13 18:43:41 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|