tobymaxham/array-faker-redactor

A PHP package to redact or fake array values by their keys.


Keywords
faker, array, laravel, Redactor, redact
License
MIT

Documentation

TobyMaxham Array Faker Redactor

A PHP package to redact or fake array values by their keys no matter how deep the array.

Latest Version on Packagist GitHub commits Total Downloads GitHub contributors GitHub issues

Notice

This packages uses the mtownsend/array-redactor package by mtownsend5512 and the Faker library by fzaninotto. So for more details to those packages look at the repositories readme files:

Why

Sometimes you need to customized your data to protect the privacy of your users or the security of your application. This is no longer a problem with this package.

With this package, an element of an array or a JSON, no matter how deep, can be easily deleted, redact or faked. This allows you to customize the response of your server or api and pass it on without worry.

Installation

Install via composer:

composer require tobymaxham/array-faker-redactor

Quick start

Using the class

use TobyMaxham\ArrayFakerRedactor\ArrayFakerRedactor;

// An example array, maybe a request being made to/from an API application
$content = [
    'email'       => 'git2019@maxham.de',
    'phone'       => '1234567',
    'password'    => 'secret123',
    'notes'       => 'this can be removed',
    'sample_data' => 'nothing else matters',
];

$redactor = (new ArrayFakerRedactor())->content($content)->keys(['email', 'password', 'notes', 'sample_data' => 'random'])->withFaker()->redact();

// $redactor will return something like:
[
    'email'       => 'russel94@hotmail.com',
    'phone'       => '1234567',
    'password'    => ']61i8~}DJB',
    'notes'       => '[REDACTED]',
    'sample_data' => 'e2k9aDUoeXRFQzhP',
];

Advanced usage

You can also add your own FakerProvider (see Faker Docs).

$content = [
    'key' => 'some data',
];

$redactor = (new ArrayFakerRedactor())->content($content)->keys(['key' => 'myformatter'])
    ->withFaker()
    ->addFakerProvider(MyProvider::class)
    ->redact();

Testing

You can run the tests with:

./vendor/bin/phpunit

Contributing

Please see CONTRIBUTING for details.

Credits

  • TobyMaxham

License

The MIT License (MIT). Please see License File for more information.