Skip to content

rkgrep/data-anonymization

 
 

Repository files navigation

Latest Stable Version Total Downloads Build Status Scrutinizer Quality Score

Data anonymization

  • This is a simple framework-agnostic package helps you to replace any sensitive production data in your development databases. *

Installation

composer require arrilot/data-anonymization

Usage

Workflow:

  1. Create a php executable.

  2. Define how you want to anonymize your data in this file using fluent api (see example below).

  3. Make sure it is not accessable throw the web and etc.

  4. 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!';

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%