-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathexample.php
46 lines (35 loc) · 1.66 KB
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env php
<?php
use Arrilot\DataAnonymization\Anonymizer;
use Arrilot\DataAnonymization\Blueprint;
use Arrilot\DataAnonymization\Database\SqlDatabase;
require './vendor/autoload.php';
$dsn = 'mysql:dbname=test;host=127.0.0.1';
$user = 'testuser';
$password = 'test';
$database = new SqlDatabase($dsn, $user, $password);
$anonymizer = new Anonymizer($database);
// Describe `users` table.
$anonymizer->table('users', function (Blueprint $table) {
// Specify a primary key of the table. An array should be passed in for composite key.
// This step can be skipped if you have `id` as a primary key.
// You can change default primary key for all tables with `Blueprint::setDefaultPrimary('ID')`
$table->primary('id');
// Replace with static data.
$table->column('email1')->replaceWith('[email protected]');
$table->column('email2')->replaceWith('email_#row#@example.com');
// To replace with dynamic data a $generator is needed.
// Any generator object can be set like that - `$anonymizer->setGenerator($generator);`
// A simpler way is just to do `require fzaninotto/Faker` and it will be set automatically.
$table->column('email3')->replaceWith(function ($generator) {
return $generator->email;
});
// Use `where` to leave some data untouched.
// If you don't list a column here, it will be left untouched too.
$table->column('email4')->where('ID != 1')->replaceWith(function ($generator) {
return $generator->unique()->email;
});
});
$anonymizer->run();
echo 'Anonymization has been completed!';