protected function Handler::doRequest in JSON-RPC 8
Same name and namespace in other branches
- 2.x src/Handler.php \Drupal\jsonrpc\Handler::doRequest()
Executes an RPC call and returns a JSON-RPC response.
Parameters
\Drupal\jsonrpc\Object\Request $request: The JSON-RPC request.
Return value
\Drupal\jsonrpc\Object\Response|null The JSON-RPC response.
1 call to Handler::doRequest()
- Handler::batch in src/
Handler.php - Executes a batch of remote procedure calls.
File
- src/
Handler.php, line 99
Class
- Handler
- Manages all the JSON-RPC business logic.
Namespace
Drupal\jsonrpcCode
protected function doRequest(Request $request) {
// Helper closure to handle eventual exceptions.
$handle_exception = function ($e, Request $request) {
if (!$e instanceof JsonRpcException) {
$id = $request
->isNotification() ? FALSE : $request
->id();
$e = JsonRpcException::fromPrevious($e, $id);
}
return $e
->getResponse();
};
try {
$result = $this
->doExecution($request);
if ($request
->isNotification()) {
return NULL;
}
$rpc_response = $result instanceof Response ? $result : new Response(static::SUPPORTED_VERSION, $request
->id(), $result);
$methodPluginClass = $this
->getMethod($request
->getMethod())
->getClass();
$result_schema = call_user_func([
$methodPluginClass,
'outputSchema',
]);
$rpc_response
->setResultSchema($result_schema);
return $rpc_response;
} catch (\Throwable $e) {
return $handle_exception($e, $request);
} catch (\Exception $e) {
return $handle_exception($e, $request);
}
}