tobymaxham / array-faker-redactor
A PHP package to redact or fake array values by their keys.
Requires
- ext-json: *
- fzaninotto/faker: ^1.8
- mtownsend/array-redactor: ^1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.15
- phpunit/phpunit: ^8.2
This package is auto-updated.
Last update: 2024-10-15 09:30:40 UTC
README
A PHP package to redact or fake array values by their keys no matter how deep the array.
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.