tobymaxham / array-faker-redactor
一个PHP包,可以按照键值对红字或伪造数组中的值,无论数组有多深。
v1.0
2019-07-14 20:43 UTC
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-09-15 09:18:49 UTC
README
一个PHP包,可以按照键值对红字或伪造数组中的值,无论数组有多深。
注意
此包使用了由mtownsend5512提供的mtownsend/array-redactor包和fzaninotto提供的
原因
有时您需要自定义数据以保护用户的隐私或应用程序的安全性。有了这个包,这个问题就不再存在。
使用此包,无论数组或JSON中的元素有多深,都可以轻松删除、红字或伪造。这使得您能够自定义服务器或API的响应,并无需担心将其传递出去。
安装
通过composer安装
composer require tobymaxham/array-faker-redactor
快速开始
使用类
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', ];
高级用法
您还可以添加自己的FakerProvider(见Faker 文档)。
$content = [ 'key' => 'some data', ]; $redactor = (new ArrayFakerRedactor())->content($content)->keys(['key' => 'myformatter']) ->withFaker() ->addFakerProvider(MyProvider::class) ->redact();
测试
您可以使用以下命令运行测试
./vendor/bin/phpunit
贡献
有关详细信息,请参阅CONTRIBUTING。
鸣谢
- TobyMaxham
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。