private function process($json) { if (!($struct = Rpc::decode($json, $batch))) { $code = is_null($struct) ? Rpc::ERR_PARSE : Rpc::ERR_REQUEST; $data = new Response(); $data->createStdError($code); return $data->toJson(); } $this->getRequests($struct); $this->processRequests(); $data = implode(',', $this->responses); return $batch && $data ? '[' . $data . ']' : $data; }
private function checkResult() { $sent = count($this->requests); $expected = $sent - $this->notifications; if (!($struct = Rpc::decode($this->output, $batch))) { if ($expected) { $this->setError('Parse error'); } return !$expected; } if ($res = $this->checkResponses($struct, $batch)) { if (!$this->checkReceived($struct, $batch, $expected)) { return; } if ($this->multi) { $this->batch = $struct; } else { if (isset($struct->error)) { $this->setError($struct->error); $res = false; } else { $this->result = $struct->result; } } } return $res; }
private function setError($error) { if (is_string($error)) { $code = 0; $message = static::ERR_RPC_RESPONSE; $data = $error; } else { $code = $error->code; $message = $error->message; $data = null; if (isset($error->data)) { $data = is_object($error->data) ? Rpc::encode($error->data) : $error->data; } } $data = $data ? ': ' . $data : ''; $this->error = $message . " ({$code})" . $data; $this->errorCode = $code; }