-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* jmespath is now called apply and accepts different properties * Ref processor uses jmespath * Add equal processor * Add match enricher * Add if enricher * Add join enricher * Added replace enricher * Renamed date property of dateformat to input * Switch enricher uses on and options properties * Enrich processor uses an input property * Add encode enricher * Add decode enricher * Add serialize and unserialize enrichers * Add default for switch * Add numberformat enricher * Add hash enricher with hmac support * Use legalthings/jmespath.php * Add sum processor * Fix ref with jmespath * Fix crc32 hash
- Loading branch information
1 parent
0bbe18e
commit 211e209
Showing
38 changed files
with
1,750 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
namespace LegalThings\DataEnricher\Processor; | ||
|
||
use LegalThings\DataEnricher\Node; | ||
use LegalThings\DataEnricher\Processor; | ||
use StephenHill\Base58; | ||
|
||
/** | ||
* Decode processor | ||
*/ | ||
class Decode implements Processor | ||
{ | ||
use Processor\Implementation; | ||
|
||
/** | ||
* Apply processing to a single node | ||
* | ||
* @param Node $node | ||
*/ | ||
public function applyToNode(Node $node) | ||
{ | ||
$instruction = $node->getInstruction($this); | ||
|
||
if (is_array($instruction) || is_object($instruction)) { | ||
$instruction = (object)$instruction; | ||
} | ||
|
||
if (!isset($instruction) || !isset($instruction->input) || !isset($instruction->algo)) { | ||
return; | ||
} | ||
|
||
if (!method_exists($this, $instruction->algo)) { | ||
return; | ||
} | ||
|
||
$result = call_user_func_array([$this, $instruction->algo], [$instruction->input]); | ||
|
||
$node->setResult($result); | ||
} | ||
|
||
|
||
/** | ||
* Base64 decode | ||
* | ||
* @param string $input | ||
*/ | ||
public function base64($input) | ||
{ | ||
return base64_decode($input); | ||
} | ||
|
||
/** | ||
* Base58 decode | ||
* | ||
* @param string $input | ||
*/ | ||
public function base58($input) | ||
{ | ||
$base58 = new Base58(); | ||
return $base58->decode($input); | ||
} | ||
|
||
/** | ||
* Url decode | ||
* | ||
* @param string $input | ||
*/ | ||
public function url($input) | ||
{ | ||
return urldecode($input); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
namespace LegalThings\DataEnricher\Processor; | ||
|
||
use LegalThings\DataEnricher\Node; | ||
use LegalThings\DataEnricher\Processor; | ||
use StephenHill\Base58; | ||
|
||
/** | ||
* Encode processor | ||
*/ | ||
class Encode implements Processor | ||
{ | ||
use Processor\Implementation; | ||
|
||
/** | ||
* Apply processing to a single node | ||
* | ||
* @param Node $node | ||
*/ | ||
public function applyToNode(Node $node) | ||
{ | ||
$instruction = $node->getInstruction($this); | ||
|
||
if (is_array($instruction) || is_object($instruction)) { | ||
$instruction = (object)$instruction; | ||
} | ||
|
||
if (!isset($instruction) || !isset($instruction->input) || !isset($instruction->algo)) { | ||
return; | ||
} | ||
|
||
if (!method_exists($this, $instruction->algo)) { | ||
return; | ||
} | ||
|
||
$result = call_user_func_array([$this, $instruction->algo], [$instruction->input]); | ||
|
||
$node->setResult($result); | ||
} | ||
|
||
|
||
/** | ||
* Base64 encode | ||
* | ||
* @param string $input | ||
*/ | ||
public function base64($input) | ||
{ | ||
return base64_encode($input); | ||
} | ||
|
||
/** | ||
* Base58 encode | ||
* | ||
* @param string $input | ||
*/ | ||
public function base58($input) | ||
{ | ||
$base58 = new Base58(); | ||
return $base58->encode($input); | ||
} | ||
|
||
/** | ||
* Url encode | ||
* | ||
* @param string $input | ||
*/ | ||
public function url($input) | ||
{ | ||
return urlencode($input); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace LegalThings\DataEnricher\Processor; | ||
|
||
use LegalThings\DataEnricher\Node; | ||
use LegalThings\DataEnricher\Processor; | ||
|
||
/** | ||
* Equal processor | ||
*/ | ||
class Equal implements Processor | ||
{ | ||
use Processor\Implementation; | ||
|
||
/** | ||
* Apply processing to a single node | ||
* | ||
* @param Node $node | ||
*/ | ||
public function applyToNode(Node $node) | ||
{ | ||
$instruction = $node->getInstruction($this); | ||
|
||
if (!is_array($instruction) || count($instruction) !== 2) { | ||
$node->setResult(false); | ||
} | ||
|
||
// might want to improve this check for different types using a library | ||
$node->setResult($instruction[0] == $instruction[1]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?php | ||
|
||
namespace LegalThings\DataEnricher\Processor; | ||
|
||
use LegalThings\DataEnricher\Node; | ||
use LegalThings\DataEnricher\Processor; | ||
use StephenHill\Base58; | ||
|
||
/** | ||
* Hash processor | ||
*/ | ||
class Hash implements Processor | ||
{ | ||
use Processor\Implementation; | ||
|
||
/** | ||
* Apply processing to a single node | ||
* | ||
* @param Node $node | ||
*/ | ||
public function applyToNode(Node $node) | ||
{ | ||
$instruction = $node->getInstruction($this); | ||
|
||
if (is_array($instruction) || is_object($instruction)) { | ||
$instruction = (object)$instruction; | ||
} | ||
|
||
if (!isset($instruction) || !isset($instruction->input) || !isset($instruction->algo)) { | ||
return; | ||
} | ||
|
||
if (!method_exists($this, $instruction->algo)) { | ||
return; | ||
} | ||
|
||
$hmac = isset($instruction->hmac) ? $instruction->hmac : null; | ||
$result = call_user_func_array([$this, $instruction->algo], [$instruction->input, $hmac]); | ||
|
||
$node->setResult($result); | ||
} | ||
|
||
|
||
/** | ||
* md5 hash | ||
* | ||
* @param string $input | ||
* @param string $hmac | ||
*/ | ||
public function md5($input, $hmac = null) | ||
{ | ||
return $hmac ? | ||
hash_hmac('md5', $input, $hmac) : | ||
hash('md5', $input); | ||
} | ||
|
||
/** | ||
* sha1 hash | ||
* | ||
* @param string $input | ||
* @param string $hmac | ||
*/ | ||
public function sha1($input, $hmac = null) | ||
{ | ||
return $hmac ? | ||
hash_hmac('sha1', $input, $hmac) : | ||
hash('sha1', $input); | ||
} | ||
|
||
/** | ||
* sha256 hash | ||
* | ||
* @param string $input | ||
* @param string $hmac | ||
*/ | ||
public function sha256($input, $hmac = null) | ||
{ | ||
return $hmac ? | ||
hash_hmac('sha256', $input, $hmac) : | ||
hash('sha256', $input); | ||
} | ||
|
||
/** | ||
* sha512 hash | ||
* | ||
* @param string $input | ||
* @param string $hmac | ||
*/ | ||
public function sha512($input, $hmac = null) | ||
{ | ||
return $hmac ? | ||
hash_hmac('sha512', $input, $hmac) : | ||
hash('sha512', $input); | ||
} | ||
|
||
/** | ||
* crc32 hash | ||
* | ||
* @param string $input | ||
* @param string $hmac | ||
*/ | ||
public function crc32($input, $hmac = null) | ||
{ | ||
return $hmac ? | ||
hash_hmac('crc32', $input, $hmac) : | ||
hash('crc32', $input); | ||
} | ||
} |
Oops, something went wrong.