protected function HttpController::serializeRpcResponse in JSON-RPC 2.x
Same name and namespace in other branches
- 8 src/Controller/HttpController.php \Drupal\jsonrpc\Controller\HttpController::serializeRpcResponse()
Serializes the RPC response object into JSON.
Parameters
\Drupal\jsonrpc\Object\Response[] $rpc_responses: The response objects.
bool $is_batched_response: True if this is a batched response.
Return value
string The serialized JSON-RPC response body.
1 call to HttpController::serializeRpcResponse()
- HttpController::getHttpResponse in src/
Controller/ HttpController.php - Map RPC response(s) to an HTTP response.
File
- src/
Controller/ HttpController.php, line 259
Class
- HttpController
- The main front controller.
Namespace
Drupal\jsonrpc\ControllerCode
protected function serializeRpcResponse(array $rpc_responses, $is_batched_response) {
$context = new Context([
RpcResponseFactory::RESPONSE_VERSION_KEY => $this->handler
->supportedVersion(),
RpcRequestFactory::REQUEST_IS_BATCH_REQUEST => $is_batched_response,
]);
// This following is needed to prevent the serializer from using array
// indices as JSON object keys like {"0": "foo", "1": "bar"}.
$data = array_values($rpc_responses);
$normalizer = new RpcResponseFactory($this->validator);
return Json::encode($normalizer
->transform($data, $context));
}