2016-01-29 18:04:48 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class RequestProxy
|
|
|
|
* @package RetailCrm\Component
|
|
|
|
*/
|
|
|
|
class RetailcrmProxy
|
|
|
|
{
|
|
|
|
|
|
|
|
private $api;
|
|
|
|
private $log;
|
|
|
|
|
|
|
|
public function __construct($url, $key, $log)
|
|
|
|
{
|
|
|
|
$this->api = new RetailcrmApiClient($url, $key);
|
|
|
|
$this->log = $log;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function __call($method, $arguments)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$response = call_user_func_array(array($this->api, $method), $arguments);
|
2017-04-07 12:35:53 +03:00
|
|
|
$date = date('[Y-m-d H:i:s]');
|
2016-01-29 18:04:48 +03:00
|
|
|
|
|
|
|
if (!$response->isSuccessful()) {
|
2017-04-07 12:35:53 +03:00
|
|
|
error_log($date . " [$method] " . $response->getErrorMsg() . "\n", 3, $this->log);
|
2016-01-29 18:04:48 +03:00
|
|
|
if (isset($response['errors'])) {
|
|
|
|
$error = implode("\n", $response['errors']);
|
2017-04-07 12:35:53 +03:00
|
|
|
error_log($date .' '. $error . "\n", 3, $this->log);
|
2016-01-29 18:04:48 +03:00
|
|
|
}
|
|
|
|
$response = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
} catch (CurlException $e) {
|
2017-04-07 12:35:53 +03:00
|
|
|
error_log($date . " [$method] " . $e->getMessage() . "\n", 3, $this->log);
|
2016-01-29 18:04:48 +03:00
|
|
|
return false;
|
|
|
|
} catch (InvalidJsonException $e) {
|
2017-04-07 12:35:53 +03:00
|
|
|
error_log($date . " [$method] " . $e->getMessage() . "\n", 3, $this->log);
|
2016-01-29 18:04:48 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|