You are here

protected function RpcRequestFactory::isBatchRequest in JSON-RPC 2.x

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

Determine if the request is a batch request.

Parameters

array $data: The raw HTTP request data.

Return value

bool Whether the HTTP request contains more than one RPC request.

Throws

\Drupal\jsonrpc\Exception\JsonRpcException Thrown if the request contains RPC requests without a 'jsonrpc' member.

1 call to RpcRequestFactory::isBatchRequest()
RpcRequestFactory::doTransform in src/Shaper/RpcRequestFactory.php

File

src/Shaper/RpcRequestFactory.php, line 199

Class

RpcRequestFactory
Creates RPC Request objects.

Namespace

Drupal\jsonrpc\Shaper

Code

protected function isBatchRequest(array $data) {
  if (isset($data['jsonrpc'])) {
    return FALSE;
  }
  $supported_version = $this->handler
    ->supportedVersion();
  $filter = function ($version) use ($supported_version) {
    return $version === $supported_version;
  };
  if (count(array_filter(array_column($data, 'jsonrpc'), $filter)) === count($data)) {
    return TRUE;
  }
  throw JsonRpcException::fromError(Error::invalidRequest("Every request must include a 'jsonrpc' member with a value of {$supported_version}."));
}