sysvyz / hurl
PHP7 language wrapper
Requires
- php: >=7.0.0
Requires (Dev)
- phpunit/phpunit: 5.3.*
- symfony/filesystem: ^3.1
This package is not auto-updated.
Last update: 2025-01-30 02:53:06 UTC
README
Hurl is a data transformation framework, designed to compose complex transformations.
Installation
You will need composer require sysvyz/hurl
Usage
Hurl is designed to build algorithms as datastructures. Each algorithm is represented by a tree. A tree is represented by its root node. Trees should be stateless (and immutable) in order to reuse them.
A Node
represents a data transformation.
Creating Nodes
A Node is basically wrapper for function
s or Closure
s if you like.
Like functions Nodes have inputs(parameters) and a output.
$fromHex = Node::call(function ($data) { return hexdec($data); }); var_dump($fromHex('a')); //int(10)
Build-in transformations
Nodes are transformation rules. There are several build-in php functions wrapped as Node
$explode = Node::explode('.'); var_dump($explode('a.b')); //array(2) { // [0]=> // string(1) "a" // [1]=> // string(1) "b" //}
Chained transformations
Nodes can be chained to perform multiple consecutive transformations
$chain = $explode->implode('-'); var_dump($chain('a.b')); //string(3) "a-b"
Map
One of the most common transformation is array_map
. Node provides a convenient way of performing those operations.
Since the callback
function of array_map
is nothing else than a transformation, it's obvious to use Nodes as callbacks.
$map = $explode->map($fromHex)->implode('.'); var_dump($map('a.b')); //string(5) "10.11"
Sort
$sort = Node::ARRAY()->sort(function ($a,$b){ return $a-$b; }); var_dump($sort([2,5,3,4,1])); //array(5) { // [0]=> // int(1) // [1]=> // int(2) // [2]=> // int(3) // [3]=> // int(4) // [4]=> // int(5) //}