-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.php
More file actions
35 lines (26 loc) · 1.01 KB
/
Copy pathserver.php
File metadata and controls
35 lines (26 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
declare(strict_types=1);
use OperationHardcode\PhpRpcServer\InvokableRpcHandler;
use OperationHardcode\PhpRpcServer\RpcRequest;
use OperationHardcode\PhpRpcServer\RpcResponse;
use OperationHardcode\PhpRpcServer\RpcServer;
require_once __DIR__.'/../vendor/autoload.php';
final class MessageHandler
{
public function __invoke(RpcRequest $request, ?RpcResponse $response): ?RpcResponse
{
return $response;
}
}
$handler = new InvokableRpcHandler([
'posts.add' => function (RpcRequest $request, RpcResponse $response): RpcResponse {
return $response;
},
'messages.get' => new MessageHandler(),
]);
$handler->add('posts.get', function (RpcRequest $request, ?RpcResponse $response): ?RpcResponse {
return $response;
});
$server = new RpcServer($handler);
$response = $server->process('[{"jsonrpc": "2.0", "method": "messages.get", "params": {"name": "User"}},{"jsonrpc": "2.0", "method": "messages.get1", "id": 2}]');
echo json_encode($response, JSON_UNESCAPED_SLASHES) . \PHP_EOL;