You are here

protected function RpcResponseFactory::doTransform in JSON-RPC 8

Same name and namespace in other branches
  1. 2.x src/Shaper/RpcResponseFactory.php \Drupal\jsonrpc\Shaper\RpcResponseFactory::doTransform()

File

src/Shaper/RpcResponseFactory.php, line 84

Class

RpcResponseFactory
Creates RPC Response objects.

Namespace

Drupal\jsonrpc\Shaper

Code

protected function doTransform($data, Context $context) {
  $this
    ->setOutputSchema($data[0]
    ->getResultSchema());
  $output = array_map(function (Response $response) use ($context) {
    try {
      return $this
        ->doNormalize($response, $context);
    } catch (\Exception $e) {
      return JsonRpcException::fromPrevious($e, $response
        ->id(), $context[static::RESPONSE_VERSION_KEY]);
    }
  }, $data);
  return $context[static::REQUEST_IS_BATCH_REQUEST] ? $output : reset($output);
}