sergeyfast/eazy-jsonrpc

支持SMD & Swagger的PHP JSON-RPC 2.0服务器/客户端实现

v3.0.3 2021-11-16 13:33 UTC

This package is auto-updated.

Last update: 2024-09-16 20:01:56 UTC


README

Latest Version Total Downloads

通过SMD自动生成客户端类实现PHP JSON-RPC 2.0服务器/客户端

服务器

通过 /server.php?smd 可用SMD模式

公共命名空间

  • 从BaseJsonRpcServer继承你的暴露类或创建 new BaseJsonRpcServer( $instance );
  • $server->Execute();

多个命名空间

  • 创建 new BaseJsonRpcServer();
  • 调用 $server->RegisterInstance( $instance, $namespace ),根据需要多次调用
  • $server->Execute();

客户端

  • 从生成器 php JsonRpcClientGenerator.php <smd-file> <class-name> 生成客户端
  • 使用它
$client = <class-name>::GetInstance(<url>);

try {  
  $result = $client->Method(); 
} catch (BaseJsonRpcException $e) {
  // work with exception
}

通过 rpcgen 生成的具有类型返回值的客户端

  • 使用 rpcgen 从SMD模式生成客户端并保存到 RpcClient.php
  • 使用它
$client = RpcClient::GetInstance(<url>);

try {  
  $result = $client->Method(); 
} catch (BaseJsonRpcException $e) {
  // work with exception
}

文档

  • cd generator
  • php SmdToSwaggerConverter.php 'http://eazyjsonrpc/tests/example-server.php?smd' eazyjsonrpc ../doc/swagger.json
  • 打开 http://eazyjsonrpc/doc/