robertasproniu / php-json-rpc
1.0.0
2017-07-18 06:54 UTC
Requires
- php: >=5.6
This package is not auto-updated.
Last update: 2024-09-29 03:41:47 UTC
README
安装
使用 Composer
"require" : { "robertasproniu/php-json-rpc": "~1.0" }
初始化
require_once 'vendor/autoload.php'; use JsonRpc\Server; $server = new Server();
定义回调函数
$server ->withCallback('add', function($a, $b) { return $a + $b; }) // OR ->withCallback('substract', 'className', 'methodName');
定义中间件
$server ->withMiddleware(function($request, $response) { // add logic here return true; // will invalidate middleware });
运行服务器
$server->execute(); // return json // OR $server->execute($payload); // pass json payload