TobyMaxham Array Faker Redactor
A PHP package to redact or fake array values by their keys no matter how deep the array.
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.
Install via composer:
composer require tobymaxham/array-faker-redactor
Using the class
use TobyMaxham\ArrayFakerRedactor\ArrayFakerRedactor; // An example array, maybe a request being made to/from an API application $content = [ 'email' => 'firstname.lastname@example.org', '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' => 'email@example.com', 'phone' => '1234567', 'password' => ']61i8~}DJB', 'notes' => '[REDACTED]', 'sample_data' => 'e2k9aDUoeXRFQzhP', ];
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();
You can run the tests with:
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.