psx/openrpc
Composer 安装命令:
composer require psx/openrpc
包简介
Model classes to generate an OpenRPC specification in a type-safe way
README 文档
README
This library contains model classes to generate an OpenRPC specification in a type-safe way. The models are
automatically generated based on the TypeSchema specification (s. typeschema.json). The
following example shows how you can generate an OpenRPC spec:
$license = new License(); $license->setName('MIT'); $info = new Info(); $info->setVersion('1.0.0'); $info->setTitle('Petstore'); $info->setLicense($license); $server = new Server(); $server->setUrl('http://localhost:8080'); $params = []; $content = new ContentDescriptor(); $content->setName('limit'); $content->setDescription('How many items to return at one time (max 100)'); $content->setRequired(false); $content->setSchema((object) ['type' => 'integer', 'minimum' => 1]); $params[] = $content; $result = new ContentDescriptor(); $result->setName('pets'); $result->setDescription('A paged array of pets'); $result->setSchema((object) ['$ref' => '#/components/schemas/Pets']); $errors = []; $error = new Error(); $error->setCode(100); $error->setMessage('pets busy'); $errors[] = $error; $methods = []; $method = new Method(); $method->setName('list_pets'); $method->setSummary('List all pets'); $method->setParams($params); $method->setResult($result); $method->setErrors($errors); $methods[] = $method; $schemas = new Schemas(); $schemas->put('Pet', [ 'required' => ['id', 'name'], 'properties' => [ 'id' => ['type' => 'integer', 'format' => 'int64'], 'name' => ['type' => 'string'], 'tag' => ['type' => 'string'], ] ]); $schemas->put('Pets', [ 'type' => 'array', 'items' => ['$ref' => '#/components/schemas/Pet'], ]); $components = new Components(); $components->setSchemas($schemas); $openRPC = new OpenRPC(); $openRPC->setInfo($info); $openRPC->setServers([$server]); $openRPC->setMethods($methods); $openRPC->setComponents($components); echo json_encode($openRPC, JSON_PRETTY_PRINT);
This would result in the following JSON:
{
"openrpc": "1.3.0",
"info": {
"title": "Petstore",
"license": {
"name": "MIT"
},
"version": "1.0.0"
},
"servers": [
{
"url": "http:\/\/localhost:8080"
}
],
"methods": [
{
"name": "list_pets",
"summary": "List all pets",
"params": [
{
"name": "limit",
"description": "How many items to return at one time (max 100)",
"required": false,
"schema": {
"type": "integer",
"minimum": 1
}
}
],
"result": {
"name": "pets",
"description": "A paged array of pets",
"schema": {
"$ref": "#\/components\/schemas\/Pets"
}
},
"errors": [
{
"code": 100,
"message": "pets busy"
}
]
}
],
"components": {
"schemas": {
"Pet": {
"required": [
"id",
"name"
],
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
},
"tag": {
"type": "string"
}
}
},
"Pets": {
"type": "array",
"items": {
"$ref": "#\/components\/schemas\/Pet"
}
}
}
}
}
Contribution
If you want to suggest changes please only change the typeschema.json specification and then run
the php gen.php script to regenerate all model classes.
psx/openrpc 适用场景与选型建议
psx/openrpc 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 17.63k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2023 年 04 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「model」 「dto」 「openrpc」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 psx/openrpc 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 psx/openrpc 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 psx/openrpc 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP library for the MUMSYS project
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
A simple library that allows transform any kind of data to native php data or whatever
Interfaces for web resource models and services to retrieve and create them
TODO
RPC implementation for PHP supporting JSON-RPC 2.0 and XML-RPC with OpenRPC specification support
统计信息
- 总下载量: 17.63k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 18
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2023-04-07