veejay/jsonrpc
Composer 安装命令:
composer require veejay/jsonrpc
包简介
JSONRPC server and client
README 文档
README
Jsonrpc 2.0 for PHP over HTTP(S).
Examples
Server
At first, you have to extend Veejay\Jsonrpc\Api class and add required methods:
<?php use Veejay\Jsonrpc\Api; use Veejay\Jsonrpc\Exception\InvalidParamsException; class MyApi extends Api { protected const TOKEN = 'qwerty'; public function __call(string $name, array $arguments): mixed { if (!isset($arguments['token']) || self::TOKEN !== $arguments['token']) { throw new InvalidParamsException('Invalid token'); } unset($arguments['token']); if (method_exists($this, $name)) { return call_user_func_array([$this, $name], $arguments); } return parent::__call($name, $arguments); } public function publicMethod(int $id): string { return 'Your id: ' . $id; } protected function protectedMethod() { return 'Protected'; } }
Then run Server with the following code:
<?php use Veejay\Jsonrpc\Server; $server = new Server(new MyApi); echo $response = $server->run();
Client
<?php use Veejay\Jsonrpc\Client; $client = new Client('https://jsonrpc/server/address'); $query = $client->query('publicMethod', ['id' => 1]); // Your id: 1 $query = $client->query('protectedMethod', ['token' => 'qwerty']); // Protected $client->notify('publicMethod'); $client->send();
You will receive the response from server in $query variables.
Requirements
- PHP 8.0+
Installation
composer require "veejay/jsonrpc"
统计信息
- 总下载量: 18
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-02-12