You are here

protected function RpcResponseFactory::doNormalize in JSON-RPC 2.x

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

Performs the actual normalization.

Parameters

\Drupal\jsonrpc\Object\Response $response: The RPC Response object to return.

\Shaper\Util\Context $context: The context object.

Return value

array The normalized response.

1 call to RpcResponseFactory::doNormalize()
RpcResponseFactory::doTransform in src/Shaper/RpcResponseFactory.php

File

src/Shaper/RpcResponseFactory.php, line 108

Class

RpcResponseFactory
Creates RPC Response objects.

Namespace

Drupal\jsonrpc\Shaper

Code

protected function doNormalize(Response $response, Context $context) {
  $normalized = [
    'jsonrpc' => $context[static::RESPONSE_VERSION_KEY],
    'id' => $response
      ->id(),
  ];
  if ($response
    ->isResultResponse()) {
    $normalized['result'] = $response
      ->getResult();
  }
  if ($response
    ->isErrorResponse()) {
    $error = $response
      ->getError();
    $normalized['error'] = [
      'code' => $error
        ->getCode(),
      'message' => $error
        ->getMessage(),
      'data' => $error
        ->getData(),
    ];
  }
  return $normalized;
}