forked from arrilot/data-anonymization
/
example.php
40 lines (30 loc) · 1.12 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
#!/usr/bin/env php
<?php
use Arrilot\DataAnonymization\Anonymizer;
use Arrilot\DataAnonymization\Blueprint;
use Arrilot\DataAnonymization\Database\SqlDatabase;
use Faker\Generator as Faker;
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. For composite key an array should be passed in.
// This step can be skipped if you have `id` as a primary key.
$table->primary('id');
// Replace with static data.
$table->column('email')->replaceWith('john@example.com');
// Replace with dynamic data.
$table->column('email2')->replaceWith(function (Faker $faker) {
return $faker->email;
});
// Use some constraints.
$table->column('email3')->where('ID != 1')->replaceWith(function (Faker $faker) {
return $faker->unique()->email;
});
});
$anonymizer->run();
echo 'Anonymization has been completed!';