PHP code example of felixfbecker / advanced-json-rpc

1. Go to this page and download the library: Download felixfbecker/advanced-json-rpc library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

felixfbecker / advanced-json-rpc example snippets


use AdvancedJsonRpc\Dispatcher;

class Argument 
{
    public $aProperty;
}

class Target
{
    public function someMethod(Argument $arg)
    {
        // $arg instanceof Argument === true
        // $arg->aProperty === 123
        return 'Hello World';
    }
}

$dispatcher = new Dispatcher(new Target());

$result = $dispatcher->dispatch('
    {
        "jsonrpc": "2.0",
        "id": 1,
        "method": "someMethod", 
        "params": {
            "arg": {"aProperty": 123}
        }
    }
');

// $result === "Hello World"

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"
        }
    }
');

// $result === "Thank you for this information"