Skip to content

Commit

Permalink
Don't return null error
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfbecker committed Sep 1, 2016
1 parent 6f3fc21 commit f9d7354
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
9 changes: 8 additions & 1 deletion lib/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

namespace AdvancedJsonRpc;

use JsonSerializable;

/**
* Base message
*/
abstract class Message
abstract class Message implements JsonSerializable
{
/**
* A String specifying the version of the JSON-RPC protocol. MUST be exactly "2.0".
Expand Down Expand Up @@ -41,4 +43,9 @@ public function __toString(): string
{
return json_encode($this);
}

public function jsonSerialize()
{
return ['jsonrpc' => $this->jsonrpc];
}
}
16 changes: 15 additions & 1 deletion lib/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@

namespace AdvancedJsonRpc;

use JsonSerializable;

/**
* When a rpc call is made, the Server MUST reply with a Response, except for in the case of Notifications. The Response
* is expressed as a single JSON Object, with the following members:
*/
class Response extends Message
class Response extends Message implements JsonSerializable
{
/**
* This member is REQUIRED. It MUST be the same as the value of the id member in the Request Object. If there was an
Expand Down Expand Up @@ -55,4 +57,16 @@ public function __construct($id, $result, ResponseError $error = null)
$this->result = $result;
$this->error = $error;
}

public function jsonSerialize()
{
$json = parent::jsonSerialize();
$json['id'] = $this->id;
if (isset($this->error)) {
$json['error'] = $this->error;
} else {
$json['result'] = $this->result;
}
return $json;
}
}

0 comments on commit f9d7354

Please sign in to comment.