\Nano4\Utils\JSONRPCServer

A simple JSON-RPC server framework.

Use this Trait in your server class.

Define methods that will be your public API.

If a method is successful, return whatever scalar or object you want to be returned as the 'result' member of the response.

If a method fails, you can throw an Exception or any Exception subclass. There are some predefined Exceptions included in this class, the most useful one for your RPC methods being 'InvalidParams'. If you make your own, be sure to update the 'code'. If you define a getData() method in your custom Exception classes, it can be used to retreive the 'data' portion of the JSON-RPC Error object.

Then using whatever transport you want, send incoming requests to the $server->handle_jsonrpc_request(); method.

Summary

Methods
Properties
Constants
handle_jsonrpc_request()
No public properties found
No constants found
handle_jsonrpc_batch_request()
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

handle_jsonrpc_request()

handle_jsonrpc_request(Mixed  $request, Array  $opts = array()) : Mixed

Process a JSON-RPC request.

Parameters

Mixed $request

Either the JSON text, Array or object.

Array $opts

Optional settings.

Returns

Mixed —

The response, see below for the possible formats.

Options:

'v1errors' If true, we use the ServerError structure even on JSON-RPC 1.0 requests. Otherwise version 1.0 will use the error message as a string.

'v1named' If true, we allow named parameters in version 1.0 requests. This is technically against the spec, but plenty of implementations use it, so we support it.

'asobject' If true, we return the ServerResponse object. If false, we return a JSON string.

'debug' If true, we enable some debugging code.

'inbatch' DO NOT USE, this is used internally to indicate we are in a batch operation.

handle_jsonrpc_batch_request()

handle_jsonrpc_batch_request(  $requests,   $opts) 

Parameters

$requests
$opts