定制 scaytrase/json-rpc-client 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

scaytrase/json-rpc-client

最新稳定版本:1.0.2

Composer 安装命令:

composer require scaytrase/json-rpc-client

包简介

JSON-RPC 2.0 Client implementation

README 文档

README

Build Status Code Coverage Scrutinizer Code Quality SensioLabsInsight

Latest Stable Version Total Downloads Latest Unstable Version

JSON-RPC 2.0 Client implementation

Extension of scaytrase/rpc-common

  • JSON RPC Interfaces
  • JSON RPC client
  • Async with Guzzle
  • Automatic batch with multiple requests or LazyClientDecorator

JSON-RPC 2.0 Specification

Usage

  1. Configure a Guzzle client.
  2. Instantiate the client:
use ScayTrase\Api\JsonRpc\JsonRpcClient; $client = new JsonRpcClient($guzzleClient, 'http://endpoint/url/');
  1. Optionally pass the ID generator as third argument and the PSR-3 logger as the fourth argument

Simple UUID generator and PSR-3 NullLogger are used by default. ID is generated for RpcRequestInterface instances. If request is instance of JsonRpcRequestInterface and does not contain an ID assigned, the request is traited as notification request and will not receive the response from server.

  1. Create a RpcRequestInterface instance

With JsonRpcRequest class:

$request = new \ScayTrase\Api\JsonRpc\JsonRpcRequest('my/method', ['param1' => 'val1'], 'request_id'); $notification = new \ScayTrase\Api\JsonRpc\JsonRpcRequest('my/method', ['param1' => 'val1']);

With JsonRpcNotification class:

$notification = new \ScayTrase\Api\JsonRpc\JsonRpcNotification('my/method', ['param1' => 'val1']);

With custom RpcRequestInterface implementation:

final class MyRpcRequest implements \ScayTrase\Api\Rpc\RpcRequestInterface { public function getMethod() { return 'my/method'; } public function getParameters() { return ['param1' => 'val1']; } } $request = new MyRpcRequest;
  1. Call the client
/** @var \ScayTrase\Api\Rpc\RpcClientInterface $client */ /** @var \ScayTrase\Api\Rpc\RpcRequestInterface $request */ $collection = $client->invoke($request); $collection = $client->invoke([$request]);

The collection object contains the mapping between the requests and the responses

/** @var \ScayTrase\Api\Rpc\RpcRequestInterface $request */ /** @var \ScayTrase\Api\Rpc\ResponseCollectionInterface $collection */ $response = $collection->getResponse($request);

Decorating

Refer scaytrase/rpc-common base library for some useful decorators:

  • CacheableRpcClient
  • LazyRpcClient
  • LoggableRpcClient
  • ProfiledClient
  • TraceableClient

统计信息

  • 总下载量: 153.57k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 1
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固