-
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.
- Loading branch information
1 parent
3675c94
commit f6820de
Showing
7 changed files
with
209 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ $ curl -#fL "$(curl -s https://api.github.com/repos/NINEJKH/myformer/releases/la | |
|
||
## Example | ||
|
||
create structure dump | ||
### create structure dump | ||
|
||
```bash | ||
$ mysqldump \ | ||
|
@@ -22,7 +22,7 @@ $ mysqldump \ | |
> database_structure.sql | ||
``` | ||
|
||
create data dump | ||
### create data dump | ||
|
||
```bash | ||
$ mysqldump \ | ||
|
@@ -36,33 +36,59 @@ $ mysqldump \ | |
> database_data.sql | ||
``` | ||
|
||
create config | ||
### create config | ||
|
||
```bash | ||
$ cat <<'EOF' > .myform.json | ||
{ | ||
"table_name": [{ | ||
"columnA": { | ||
"Tel": [] | ||
"Tel": null | ||
} | ||
}, | ||
{ | ||
"columnB": { | ||
"Email": [] | ||
"Email": "qa+%[email protected]" | ||
} | ||
}, | ||
{ | ||
"columnC": { | ||
"Replace": ["foo", "bar"] | ||
"Set": "static content" | ||
} | ||
} | ||
] | ||
} | ||
EOF | ||
``` | ||
|
||
anonymise data | ||
### anonymise data | ||
|
||
```bash | ||
$ myformer | ||
$ myformer transform *_data.sql | ||
``` | ||
|
||
This will create a file with the same name + postfixed with "+transformed". | ||
|
||
## Rules | ||
|
||
|
||
Anonymise Email addresses. | ||
|
||
Accepts a string parameter, `%s` will be replaced with the first 16 chars | ||
of the md5 hash of the original value. | ||
|
||
### Ref | ||
|
||
Set column value from another column value. | ||
|
||
Accepts a string parameter, which will be used as column name of the | ||
source value. | ||
|
||
### Set | ||
|
||
Statically set the value of the string parameter | ||
|
||
### Tel | ||
|
||
Random telphone-like number (999 + 10-digits) |
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,13 @@ | ||
<?php | ||
|
||
namespace App\Transformer; | ||
|
||
abstract class Condition implements ConditionInterface | ||
{ | ||
protected $param; | ||
|
||
public function __construct($param) | ||
{ | ||
$this->param = $param; | ||
} | ||
} |
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,8 @@ | ||
<?php | ||
|
||
namespace App\Transformer; | ||
|
||
interface ConditionInterface | ||
{ | ||
public function evaluate($against); | ||
} |
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,13 @@ | ||
<?php | ||
|
||
namespace App\Transformer\Conditions; | ||
|
||
use App\Transformer\Condition; | ||
|
||
class Contains extends Condition | ||
{ | ||
public function evaluate($against) | ||
{ | ||
return (bool) stripos($against, $this->param); | ||
} | ||
} |
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,43 @@ | ||
<?php | ||
|
||
namespace App\Transformer; | ||
|
||
class Rule | ||
{ | ||
public $column; | ||
|
||
public $name; | ||
|
||
public $param; | ||
|
||
public $condition; | ||
|
||
public function __construct($column, array $rule) | ||
{ | ||
$this->column = $column; | ||
|
||
$this->extractNameAndParam($rule); | ||
} | ||
|
||
protected function extractNameAndParam(array $rule) | ||
{ | ||
if (count($rule) === 1) { | ||
$this->name = key($rule); | ||
$this->param = current($rule); | ||
} else { | ||
if (isset($rule['Condition'])) { | ||
$condition_class = 'App\\Transformer\\Conditions\\' . key($rule['Condition']); | ||
$this->condition = new $condition_class(current($rule['Condition'])); | ||
//$this->condition = [ | ||
// 'name' => key($rule['Condition']), | ||
// 'param' => current($rule['Condition']), | ||
//]; | ||
|
||
unset($rule['Condition']); | ||
} | ||
|
||
$this->name = key($rule); | ||
$this->param = current($rule); | ||
} | ||
} | ||
} |
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,59 @@ | ||
<?php | ||
|
||
namespace App\Transformer; | ||
|
||
use Iterator; | ||
|
||
class RuleSet implements Iterator | ||
{ | ||
protected $rules = []; | ||
|
||
protected $column = []; | ||
|
||
protected $pos; | ||
|
||
public function __construct(array $rules) | ||
{ | ||
$this->rules = $rules; | ||
$this->columns = array_keys($rules); | ||
$this->pos = 0; | ||
} | ||
|
||
public function next() | ||
{ | ||
++$this->pos; | ||
} | ||
|
||
public function valid() | ||
{ | ||
return isset($this->columns[$this->pos]); | ||
} | ||
|
||
public function current() | ||
{ | ||
$column = $this->columns[$this->pos]; | ||
$rule = $this->rules[$column]; | ||
|
||
if (isset($rule[0])) { | ||
$rules = []; | ||
|
||
foreach($rule as $each) { | ||
$rules[] = new Rule($column, $each); | ||
} | ||
|
||
return $rules; | ||
} else { | ||
return new Rule($column, $rule); | ||
} | ||
} | ||
|
||
public function rewind() | ||
{ | ||
$this->pos = 0; | ||
} | ||
|
||
public function key() | ||
{ | ||
return $this->pos; | ||
} | ||
} |
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