/** * Executes API requests. * * @return string JSON encoded value */ public function execute() { if ($this->json->hasError()) { $this->jsonError(null, '-32700', null, null, true); return $this->json->encode($this->_response[0]); } if ($this->_jsonDecoded === null || $this->_jsonDecoded == []) { $this->jsonError(null, '-32600', null, null, true); return $this->json->encode($this->_response[0]); } foreach (zbx_toArray($this->_jsonDecoded) as $call) { $call = is_array($call) ? $call : [$call]; // notification if (!array_key_exists('id', $call)) { $call['id'] = null; } if (!$this->validate($call)) { continue; } list($api, $method) = array_merge(explode('.', $call['method']), [null, null]); $result = $this->apiClient->callMethod($api, $method, $call['params'], $call['auth']); $this->processResult($call, $result); } if (is_array($this->_jsonDecoded) && array_keys($this->_jsonDecoded) === range(0, count($this->_jsonDecoded) - 1)) { // Return response as encoded batch if $this->_jsonDecoded is associative array. return $this->json->encode($this->_response); } return $this->json->encode($this->_response[0]); }
public function execute($encoded = true) { $call = $this->_jsonDecoded; // notification if (!isset($call['id'])) { $call['id'] = null; } if ($this->validate($call)) { $params = isset($call['params']) ? $call['params'] : null; $auth = isset($call['auth']) ? $call['auth'] : null; list($api, $method) = explode('.', $call['method']); $result = $this->apiClient->callMethod($api, $method, $params, $auth); $this->processResult($call, $result); } if (!$encoded) { return $this->_response; } else { return $this->json->encode($this->_response); } }
/** * Call the client method and return the result. * * @param string $method API method name * @param mixed $params API method parameters * * @return CApiClientResponse */ protected function callClientMethod($method, $params) { return $this->client->callMethod($this->api, $method, $params, $this->auth); }