felixfbecker/advanced-json-rpc
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
netresearch/jsonmapper | v4.4.1 | - | OSL-3.0 | prod | 1 |
phpdocumentor/reflection-docblock | 5.4.0 | - | MIT | prod |
The felixfbecker/advanced-json-rpc is an advanced implementation of JSON RPC (Remote Procedure Call) in PHP. This composer package provides basic classes for setting up requests and responses in JSONRPC. One of its standout features is its Dispatcher
class, which can decode a JSONRPC request and call the appropriate methods on a target while coercing the types of parameters by type-hints and @param
tags. It supports nested targets, thus allowing for complex function calls.
To use the felixfbecker/advanced-json-rpc
package in your PHP project, you will first need to install it via composer. Below is an example of how you can incorporate the package in your code:
use AdvancedJsonRpc\Dispatcher;
class Argument
{
public $aProperty;
}
class Target
{
public function someMethod(Argument $arg)
{
return 'Hello World';
}
}
$dispatcher = new Dispatcher(new Target());
$result = $dispatcher->dispatch('
{
"jsonrpc": "2.0",
"id": 1,
"method": "someMethod",
"params": {
"arg": {"aProperty": 123}
}
}
');
In the above example, an instance of the Dispatcher
class is created with a Target
object as the target. The Dispatcher
then decodes a JSONRPC request and calls the appropriate method on the target.
It's also possible to handle nested targets as shown below:
use AdvancedJsonRpc\Dispatcher;
class TextDocumentManager
{
public function didOpen(string $uri)
{
return 'Thank you for this information';
}
}
class LanguageServer
{
public $textDocument;
public function __construct()
{
$this->textDocument = new TextDocumentManager();
}
}
$dispatcher = new Dispatcher(new LanguageServer(), '/');
$result = $dispatcher->dispatch('
{
"jsonrpc": "2.0",
"id": 1,
"method": "textDocument/didOpen",
"params": {
"uri": "file:///c/Users/felix/test.php"
}
}
');
In this case, the method didOpen
in the TextDocumentManager
class nested inside the LanguageServer
class is called.
The official documentation for the felixfbecker/advanced-json-rpc package is available on the GitHub repository felixfbecker/php-advanced-json-rpc. The README file in the repository provides all the necessary information about the installation and how to use the package, including code examples. If you are looking to integrate advanced JSONRpc into your PHP project, this should be your primary resource.