legalthings/data-enricher
Composer 安装命令:
composer require legalthings/data-enricher
包简介
Enrich objects by processing special properties
README 文档
README
Enrich objects by processing special properties known as data instruction.
<ref>- Resolve a reference to another part of the document using a dot key path<ifset>- Checks if a reference is null. If so, replace the object by null.<switch>- Choose one of the child properties based on a property in the document<src>- Load an external resource (through HTTP)<merge>- Merge a set of objects<enrich>- Enrich an object with extra data by matching properties<tpl>- Parse text as Mustache template<transform>- Transform the input using a function. The following functions are available You can pass in a string with the following format<function>:<arg>Alternatively you can pass in an object to pass multiple args{ function: <string>, args: [...] }hash:algo- Replacealgowith the algoritmhash_hmacbase64_encodebase64_decodejson_encodejson_decodeserializeunserializestrtotimedatepublic_encryptprivate_encryptprivate_decryptgenerate_private_keygenerate_public_keygenerate_signatureverify_signature
<jmespath>- Project an object using the JMESPath query language<dateformat>- Takes a date and a format (defaults toY-m-d) and formats the accordingly. Optionally you can set the timezone if you wish to output timezone information.
Installation
composer require legalthings/data-enricher
Usage
Source
{
"foo": {
"bar": {
"qux": 12345,
},
"term": "data enrichment",
"city": "Amsterdam",
"country": "Netherlands"
},
"amount": {
"<ref>" : "foo.bar.qux"
},
"message": {
"<tpl>": "I want to go to {{ foo.city }}, {{ foo.country }}"
},
"shipping": {
"<switch>": "foo.country",
"USA": "UPS",
"Netherlands": "PostNL",
"_other": "DHL"
},
"user" : {
"<src>": "https://api.example.com/users/9870"
},
"search_results": {
"<src>": {
"<tpl>": "http://api.duckduckgo.com/?q={{ foo.term }}&format=json"
},
"<jmespath>": "RelatedTopics[].{url: FirstURL, description: Text}"
},
"profile": {
"<merge>": [
{ "<ref>": "foo.bar" },
{ "<src>": "https://api.example.com/zoo/99" },
{
"apples": 100,
"pears": 220
}
]
}
}
PHP script
$json = file_get_contents('source.json'); $object = json_decode($json); $enricher = new DataEnricher(); $enricher->applyTo($object); echo json_encode($object, JSON_PRETTY_PRINT);
Result
{
"foo": {
"bar": {
"qux": 12345,
},
"term": "data enrichment",
"city": "Amsterdam",
"country": "Netherlands"
},
"amount": 12345,
"message": "I want to go to Amsterdam, Netherlands",
"shipping": "PostNL",
"user" : {
"id": "9870",
"name": "John Doe",
"email": "john@example.com"
},
"search_results": [
{
"url": "https://duckduckgo.com/Names_Database",
"description": "Names Database - The Names Database is a partially defunct social network, owned and operated by Classmates.com, a wholly owned subsidiary of United Online. The site does not appear to be significantly updated since 2008, and has many broken links and display issues."
},
{
"url": "https://duckduckgo.com/c/Tor_hidden_services",
"description": "Tor hidden services"
},
{
"url": "https://duckduckgo.com/c/Internet_privacy_software",
"description": "Internet privacy software"
}
],
"profile": {
"qux": 12345,
"zoop": "P99",
"zooq": "Q99",
"apples": 100,
"pears": 220
}
}
legalthings/data-enricher 适用场景与选型建议
legalthings/data-enricher 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.31k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2016 年 03 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 legalthings/data-enricher 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 legalthings/data-enricher 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 3.31k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-03-14