datto / json-rpc-simple
JSON-RPC 库的请求到类映射扩展
4.0.1
2016-04-06 15:44 UTC
Requires
- datto/json-rpc: ~3.0
- monolog/monolog: ~1.0
This package is not auto-updated.
Last update: 2024-09-14 18:26:09 UTC
README
这是为php-json-rpc库提供的请求到类映射扩展。它的目的是通过自动将 JSON-RPC 的 method
和 params
参数映射到相应的 PHP 类、方法和参数,从而消除手动编写映射函数的需求。
示例
首先编写一个 API 端点
<?php namespace Datto\API; class Math { public function subtract($a, $b) { return $a - $b; } }
然后使用 API(默认命名空间 Datto\API
)
// This will instantiate an object of the type `Datto\API\Math`, // call the `subtract` method, and return a corresponding JSON-RPC response. $server = new Server(new Simple\Evaluator()); echo $server->reply('{"jsonrpc": "2.0", "method": "math/subtract", "params": {"a": 3, "b": 2}, "id": 1}');
或使用自定义根命名空间(此处为 Datto\NodeAPI
)
$server = new Server(new Simple\Evaluator(new Simple\Mapper('Datto\\NodeAPI'))); echo $server->reply('...');
要求
- PHP >= 5.3
安装
"require": { "datto/json-rpc-simple": "~4.0" }
许可协议
本软件包在开源许可协议下发布:LGPL-3.0。
作者
由 Philipp C. Heckel 编写。