Example #1
0
 public function call(MRPCJsonRequest $request)
 {
     $this->request = $request;
     $this->request->setId($this->generateId());
     $jsonRequest = json_encode($this->request->toArray());
     $ctx = stream_context_create(array('http' => array('method' => 'POST', 'header' => 'Content-Type: application/json\\r\\n', 'content' => $jsonRequest)));
     $jsonResponse = file_get_contents($this->url, false, $ctx);
     if ($jsonResponse === false) {
         throw new MRPCJsonClientException('file_get_contents failed', -32603);
     }
     $response = json_decode($jsonResponse);
     if ($response === null) {
         throw new MRPCJsonClientException('JSON cannot be decoded', -32603);
     }
     if ($response->id != $request->getId()) {
         throw new MRPCJsonClientException('Mismatched JSON-RPC IDs', -32603);
     }
     if (property_exists($response, 'result') === false) {
         throw new MRPCJsonClientException('Invalid JSON-RPC response', -32603);
     }
     $this->response = new MRPCJsonResponse();
     $this->response->fromArray($response);
 }
Example #2
0
 /**
  * @param array $json
  */
 public static function fromArray(array $json)
 {
     $response = new MRPCJsonResponse();
     $response->setError(MRPCJsonError::fromArray($json["error"]));
     $response->setId($json["id"]);
     $response->setResult($json["result"]);
 }