*/
public function __construct($config = NULL) {
$this->local = TRUE;
- $this->input = array();
- $this->lastResult = array();
+ $this->input = [];
+ $this->lastResult = [];
if (isset($config) && isset($config['server'])) {
// we are calling a remote server via REST
$this->local = FALSE;
else {
$this->uri .= '/sites/all/modules/civicrm/extern/rest.php';
}
- $this->uri .= '?json=1';
if (isset($config['key'])) {
$this->key = $config['key'];
}
return;
}
if (isset($config) && isset($config['conf_path'])) {
- define('CIVICRM_SETTINGS_PATH', $config['conf_path'] . '/civicrm.settings.php');
+ if (!defined('CIVICRM_SETTINGS_PATH')) {
+ define('CIVICRM_SETTINGS_PATH', $config['conf_path'] . '/civicrm.settings.php');
+ }
require_once CIVICRM_SETTINGS_PATH;
require_once 'CRM/Core/ClassLoader.php';
require_once 'api/api.php';
}
}
- /**
- * As of PHP 5.3.0.
- *
- * @param $name
- * @param $arguments
- */
- public static function __callStatic($name, $arguments) {
- // Should we implement it ?
- echo "Calling static method '$name' " . implode(', ', $arguments) . "\n";
- }
-
/**
* Call via rest.
*
*
* @return \stdClass
*/
- public function remoteCall($entity, $action, $params = array()) {
- $fields = "key={$this->key}&api_key={$this->api_key}";
- $query = $this->uri . "&entity=$entity&action=$action";
- $fields .= '&' . http_build_query($params);
+ private function remoteCall($entity, $action, $params = []) {
+ $query = $this->uri . "?entity=$entity&action=$action";
+ $fields = http_build_query([
+ 'key' => $this->key,
+ 'api_key' => $this->api_key,
+ 'json' => json_encode($params),
+ ]);
+
if (function_exists('curl_init')) {
// To facilitate debugging without leaking info, entity & action
// are GET, other data is POST.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $query);
- curl_setopt($ch, CURLOPT_POST, count($params) + 2);
+ curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
$res->is_error = 1;
$res->error_message = curl_error($ch);
$res->level = "cURL";
- $res->error = array('cURL error' => curl_error($ch));
+ $res->error = ['cURL error' => curl_error($ch)];
return $res;
}
curl_close($ch);
$res->is_error = 1;
$res->error_message = 'Unable to parse returned JSON';
$res->level = 'json_decode';
- $res->error = array('Unable to parse returned JSON' => $result);
+ $res->error = ['Unable to parse returned JSON' => $result];
$res->row_result = $result;
}
return $res;
*
* @return bool
*/
- public function call($entity, $action = 'Get', $params = array()) {
+ private function call($entity, $action = 'Get', $params = []) {
if (is_int($params)) {
- $params = array('id' => $params);
+ $params = ['id' => $params];
}
elseif (is_string($params)) {
$params = json_decode($params);
$this->lastResult = json_decode(json_encode(civicrm_api($entity, $action, $params)));
}
// Reset the input to be ready for a new call.
- $this->input = array();
+ $this->input = [];
if (property_exists($this->lastResult, 'is_error')) {
return !$this->lastResult->is_error;
}