You are here

public function Response::__construct in JSON-RPC 2.x

Same name and namespace in other branches
  1. 8 src/Object/Response.php \Drupal\jsonrpc\Object\Response::__construct()

Response constructor.

Parameters

string $version: The JSON-RPC version.

mixed $id: The response ID. Must match the ID of the generating request.

mixed $result: A result value. Must not be provided if an error is to be provided.

\Drupal\jsonrpc\Object\Error|null $error: An error object if the response resulted in an error. Must not be provided if a result was provided.

File

src/Object/Response.php, line 71

Class

Response
Response object to help implement JSON RPC's spec for response objects.

Namespace

Drupal\jsonrpc\Object

Code

public function __construct($version, $id, $result = NULL, Error $error = NULL, HeaderBag $headers = NULL) {
  $this
    ->assertValidResponse($version, $id, $result, $error);
  $this->version = $version;
  $this->id = $id;
  $this->headers = $headers ?? new HeaderBag();
  if (!is_null($result)) {
    $this->result = $result;
  }
  else {
    $this->error = $error;
    $this
      ->setCacheability($error);
  }
}