- This is a simple framework-agnostic package helps you to replace any sensitive production data in your development databases. *
composer require arrilot/data-anonymization
Workflow:
-
Create a php executable.
-
Define how you want to anonymize your data in this file using fluent api (see example below).
-
Make sure it is not accessable throw the web and etc.
-
Run it every time you want.
Here is an example file that illustrates api really well:
#!/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 using fzaninotto/Faker.
$table->column('email2')->replaceWith(function (Faker $faker) {
return $faker->email;
});
// Use `where` to leave some data untouched.
// If you don't list a column here, it will be left untouched too.
$table->column('email3')->where('ID != 1')->replaceWith(function (Faker $faker) {
return $faker->unique()->email;
});
});
$anonymizer->run();
echo 'Anonymization has been completed!';