felixfbecker/advanced-json-rpc
JSON-RPC 2.0 request/response helpers with a Dispatcher that decodes JSON-RPC calls and invokes target methods. Automatically coerces parameter types using type hints and @param docs, and supports nested targets via configurable method delimiters.
Install via Composer: composer require felixfbecker/advanced-json-rpc. Start with the Dispatcher class — instantiate it with a target object (e.g., a service class), then call dispatch() with raw JSON-RPC request bodies. The first real-world use is exposing internal logic over JSON-RPC, especially for protocols like LSP where method names are hierarchical (textDocument/didOpen). A minimal working example:
use AdvancedJsonRpc\Dispatcher;
class Handler {
public function hello(string $name): string {
return "Hello, {$name}!";
}
}
$dispatcher = new Dispatcher(new Handler());
echo $dispatcher->dispatch('{"jsonrpc":"2.0","id":1,"method":"hello","params":{"name":"World"}}');
// Output: "Hello, World!"
TextDocumentManager under LanguageServer::$textDocument) to support methods like "textDocument/didOpen" using the -> delimiter. Configure this via constructor or setDelimiter('/') for LSP-style paths.string $uri, int $version) and @param annotations to auto-convert JSON params into typed PHP values. Use named object props or associative arrays — the underlying jsonmapper handles mapping.ParseError, MethodNotFound, etc.) or convert uncaught exceptions to InternalError. Use Response::encode($result) to serialize valid responses or ErrorResponse for error payloads.JsonRpcController that reads request()->getContent(), instantiates the dispatcher per-request (or via a singleton-aware factory), and returns a JSON response. Avoid conflating RPC with REST — treat it as a separate endpoint (e.g., /rpc) with custom middleware for auth/logging.netresearch/jsonmapper and phpdocumentor/reflection-docblock haven’t been updated in years and may conflict with newer ecosystem versions.beforeDispatch or afterDispatch.@param annotations to avoid ambiguity. Optional params default to null if missing (fixed in v3.0.2+), but undocumented — always test edge cases like {"params":{}}.Dispatcher::__construct($target, '/', true) for additional validation. Log raw requests/responses early — the exception messages are terse but include error codes (e.g., -32601 for MethodNotFound) useful for tracing client-side issues.How can I help you explore Laravel packages today?