예제 #1
0
 public static function fromArray(array $json)
 {
     $request = new MRPCJsonRequest();
     $request->setId($json["id"]);
     $request->setId($json["method"]);
     $request->setId($json["params"]);
     return $request;
 }
예제 #2
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);
 }