legalthings / data-enricher
Enrich objects by processing special properties
Installs: 3 245
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 12
Forks: 1
Open Issues: 3
Requires
- php: >=5.5.0
- guzzlehttp/guzzle: ^6.0
- hoa/math: 1.16.08.29
- jasny/dotkey: ^1.0
- mtdowling/jmespath.php: dev-master#8ec2d692c59e45184d16b4c9160e902397cfc659
- mustache/mustache: ^2.10
- stephenhill/base58: ^1.1
Requires (Dev)
- phpunit/phpunit: ^5.0
- dev-master
- v0.8.3
- v0.8.2
- v0.8.1
- v0.8.0
- v0.7.9
- v0.7.8
- v0.7.7
- v0.7.6
- v0.7.5
- v0.7.4
- v0.7.3
- v0.7.2
- v0.7.1
- v0.7.0
- v0.6.0
- v0.5.8
- v0.5.7
- v0.5.6
- v0.5.5
- v0.5.4
- v0.5.3
- v0.5.2
- v0.5.1
- v0.5.0
- v0.4.1
- v0.4.0
- v0.3.0
- v0.2.1
- v0.2.0
- v0.1.0
- dev-fix-switch-choose
- dev-ref-dot-key
- dev-enricher-schema
- dev-fix-warnings
- dev-openssl-issues
- dev-encryption-enrichers
- dev-transform-multiple-args
- dev-integration-test
- dev-date-format
- dev-readme
- dev-transform-test
This package is auto-updated.
Last update: 2024-11-29 04:57:40 UTC
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
- Replacealgo
with the algoritmhash_hmac
base64_encode
base64_decode
json_encode
json_decode
serialize
unserialize
strtotime
date
public_encrypt
private_encrypt
private_decrypt
generate_private_key
generate_public_key
generate_signature
verify_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 } }