kelemen/json-rpc-20-processor

JSON RPC 2.0 processor library

0.2.0 2016-01-20 15:09 UTC

This package is auto-updated.

Last update: 2024-12-18 01:19:27 UTC


README

Easy JSON RPC 2.0 processor. No build in response senders, only process and return result object.

Usage

use MyHandlers\AddHandler;
use Kelemen\JsonRpc20\Processor;
use Kelemen\JsonRpc20\Processor\Transform\FractalTransform;

$raw = file_get_contents('php://input');
$handler = new AddHandler();

$processor = new Processor();

// Add new handler for method "add"
$processor->registerHandler('add', [$handler, 'add']);

// Response is Response object or array of Response object for batch request
$response = $processor->process($raw);

// Transform result to array or json
$fractalTransform = new FractalTransform();
return $fractalTransform->toArray($response);