sintese/phancackes
最新稳定版本:v0.4.0
Composer 安装命令:
composer require sintese/phancackes
包简介
README 文档
README
Case study for Tabulation and Expansion of objects built from a json-schema.
Usage
Given the definition of an object specified by a json-schema:
$schema = <<<JSON { "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "https://example.com/product.schema.json", "title": "Product", "description": "A product from Acme's catalog", "type": "object", "properties": { "productId": { "description": "The unique identifier for a product", "type": "integer" }, "dimensions": { "type": "object", "properties": { "width": { "type": "number" }, "height": { "type": "number" } } }, "tags": { "type": "array", "items": { "type": "object", "properties": { "name": { "type": "string" } } } } } } JSON
Our goal is to tabulate its content to simplify manipulation:
echo (new SchemaFlatten())->flat(new SchemaObject($schema));
The tabulated structure will compose key (path) and value (definition) at the same level:
{
"$.productId": {
"description": "The unique identifier for a product",
"type": "integer",
"path": "$.productId",
"prop": "productId"
},
"$.dimensions.width": {
"type": "number",
"path": "$.dimensions.width",
"prop": "width"
},
"$.dimensions.height": {
"type": "number",
"path": "$.dimensions.height",
"prop": "height"
},
"$.tags[0].name": {
"type": "string",
"path": "$.tags[0].name",
"prop": "name"
}
}
Having the tabulated structure in hand, we can create a flattened object to simplify its storage:
$payload = <<<JSON { "$.productId": 1, "$.dimensions.width": 3, "$.dimensions.height": 6, "$.tags[0].name": "tag" } JSON;
This same structure can later be used to recompose the original object:
echo (new SchemaFlatten())->unflat($payload);
Thus assuming the format specified by the JSON schema used as the tabulation basis:
{
"productId": 1,
"dimensions": {
"width": 3,
"height": 6
},
"tags": [
{
"name": "tag"
}
]
}
Contributions
Contributions, corrections, and improvement suggestions are very welcome.
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-02-15