You are here

protected function HttpController::getRpcRequests in JSON-RPC 8

Same name and namespace in other branches
  1. 2.x src/Controller/HttpController.php \Drupal\jsonrpc\Controller\HttpController::getRpcRequests()

Get the JSON RPC request objects for the given Request object.

Parameters

\Symfony\Component\HttpFoundation\Request $http_request: The HTTP request.

Return value

\Drupal\jsonrpc\Object\Request[] The JSON-RPC request or requests.

Throws

\Drupal\jsonrpc\Exception\JsonRpcException When there was an error handling the response.

1 call to HttpController::getRpcRequests()
HttpController::resolve in src/Controller/HttpController.php
Resolves an RPC request over HTTP.

File

src/Controller/HttpController.php, line 114

Class

HttpController
The main front controller.

Namespace

Drupal\jsonrpc\Controller

Code

protected function getRpcRequests(Request $http_request) {
  $version = $this->handler
    ->supportedVersion();
  try {
    if ($http_request
      ->getMethod() === Request::METHOD_POST) {
      $content = Json::decode($http_request
        ->getContent(FALSE));
    }
    elseif ($http_request
      ->getMethod() === Request::METHOD_GET) {
      $content = Json::decode($http_request->query
        ->get('query'));
    }
    $context = new Context([
      RpcRequestFactory::REQUEST_VERSION_KEY => $version,
    ]);
    $factory = new RpcRequestFactory($this->handler, $this->container, $this->validator);
    return $factory
      ->transform($content, $context);
  } catch (\Exception $e) {
    $id = isset($content) && is_object($content) && isset($content->id) ? $content->id : FALSE;
    throw JsonRpcException::fromPrevious($e, $id, $version);
  }
}