moaction/jsonrpc-common
Composer 安装命令:
composer require moaction/jsonrpc-common
包简介
Jsonrpc common libraries
README 文档
README
Common libraries for JSON-Rpc 2.0 protocol implementation
http://www.jsonrpc.org/specification
Libraries are used in jsonrpc-client and jsonrpc-server
Request
class \Moaction\Jsonrpc\Common\Request
Fields (getters and setters for fields):
- method
- id
- params
Methods
- toArray()
$request = new \Moaction\Jsonrpc\Common\Request $request->setId(1); $request->setMethod('getUserData'); $request->setParams(array('userId' => 4, 'field' => 'email')); // here you get valid jsonrpc 2.0 request object ready for json_encode // \InvalidArgumentException can be thrown when Request object is misconfigured (method is not set). $data = $request->toArray();
Response
class \Moaction\Jsonrpc\Common\Response
Fields (getters and setters for fields):
- result
- error
- id
Methods
- fromArray()
- hasError()
Normal response
// decoded array with jsonrpc 2.0 response $data = array( 'id' => 1, 'result' => array( 'email' => 'user@example.com', ), ); // \Moaction\Jsonrpc\Common\Exception can be thrown when object is not valid jsonrpc response $response = new \Moaction\Jsonrpc\Common\Response::fromArray($data);
Error response
// decoded array with jsonrpc 2.0 response $data = array( 'id' => 1, 'error' => array( 'code' => '20', 'message' => 'User not found', 'data' => array('userId' => 4), ), ); $response = new \Moaction\Jsonrpc\Common\Response::fromArray($data); // \Moaction\Jsonrpc\Common\Error object $error = $response->getError();
Error
class \Moaction\Jsonrpc\Common\Error
Error object. See response for example.
Exception
class \Moaction\Jsonrpc\Common\Exception
Exception for using in jsonrpc libraries
统计信息
- 总下载量: 273
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-12-06