outsidaz/laravel-data-anonymization
Composer 安装命令:
composer require outsidaz/laravel-data-anonymization
包简介
关键字:
README 文档
README
This Laravel package facilitates data anonymization, which helps organizations protect privacy, comply with regulations, reduce the risk of data breaches, and enable safe data sharing:
-
Protecting privacy: Data contains sensitive information about individuals, such as their name, address, email, phone number, and other personally identifiable information (PII). Data anonymization helps protect the privacy of individuals by removing or masking their PII from the dataset.
-
Compliance with regulations: Many countries and industries have regulations that require organizations to protect the privacy of individuals by anonymizing their data. For example, the General Data Protection Regulation (GDPR) in the European Union requires organizations to protect the privacy of individuals by anonymizing their data.
-
Reducing the risk of data breaches: Data breaches can have serious consequences for organizations and individuals, including financial loss, reputational damage, and identity theft. By anonymizing data, organizations can reduce the risk of data breaches and minimize the impact of any data breaches that do occur.
-
Enabling data sharing: Anonymized data can be shared with other organizations or researchers without violating the privacy of individuals. This can help promote collaboration and innovation in fields such as healthcare, finance, and social sciences.
Installation
You can install the package via composer:
composer require outsidaz/laravel-data-anonymization
You can publish the config file with:
php artisan vendor:publish --tag="laravel-data-anonymization-config"
This is the contents of the published config file:
return [ 'locale' => 'en_US', 'chunk_size' => 1000, 'models_path' => app_path('Models'), 'models_namespace' => '\\App\\Models', ]
Usage
Model based definitions
In any model that contains sensitive data use the Anonymizable trait and implement the anonymizableAttributes method:
<?php class User extends Authenticatable { use Anonymizable; <...> public function anonymizableAttributes(Generator $faker): array { return [ 'email' => $this->id . '@custom.dev', 'password' => 'secret', 'firstname' => $faker->firstName(), 'surname' => $faker->lastName(), 'phone' => $faker->e164PhoneNumber(), 'position' => $faker->jobTitle(), 'token' => null, ]; } // optional public function anonymizableCondition(): Builder { return self::withTrashed()->where('something', '=>', '...'); } }
Factory based definitions
To reduce the amount of necessary code, the anonymizable attributes may also be defined on your factories.
Do note that the model still needs to implement the Anonymizable to work with these definitions.
Attributes based on the factory's definition
It is possible to use the factory's definition to use as anonymizable values.
Implement the anonymizableAttributes method on your factory and return an array with keys that corresponds to the definition of the factory:
<?php class UserFactory extends Factory { public function definition(): array { return [ 'email' => $this->faker()->numberBetween(1, 100_000) . '@custom.dev', 'password' => 'secret', 'firstname' => $this->faker->firstName(), 'surname' => $this->faker->lastName(), 'phone' => $this->faker->e164PhoneNumber(), 'position' => $this->faker->jobTitle(), 'token' => null, ] } public function anonymizableAttributes(): array { return [ 'email', 'password', 'firstname', 'surname', 'phone', 'position', 'token', ] } }
This will use reduce the amount of code you need to write if the data you want to anonymize is the same as your factory's definition.
Note that only the defined keys will be anonymized!
Attributes based on a custom definition
If you prefer to still use custom values, you can still define them on the factory.
Implement the anonymizableDefinition method on your factory, and return a keyed array:
<?php class UserFactory extends Factory { public function definition(): array { return [ 'email' => $this->faker()->numberBetween(1, 100_000) . '@custom.dev', 'password' => 'secret', 'firstname' => $faker->firstName(), 'surname' => $faker->lastName(), 'phone' => $faker->e164PhoneNumber(), 'position' => $faker->jobTitle(), 'token' => null, ] } public function anonymizableDefinition(): array { return [ 'email' => $this->faker()->numberBetween(1, 100_000) . '@custom.dev', 'password' => 'secret', 'firstname' => $faker->firstName(), 'surname' => $faker->lastName(), 'phone' => $faker->e164PhoneNumber(), 'position' => $faker->jobTitle(), 'token' => $this->faker->md5(), ] } }
Defining custom values is mostly useful when used in tandem with the anonymizableAttributes method.
This allows certain attributes from the factory to be used, while still defining custom attributes when necessary:
<?php class UserFactory extends Factory { public function definition(): array { return [ 'email' => $this->faker()->numberBetween(1, 100_000) . '@custom.dev', 'password' => 'secret', 'firstname' => $faker->firstName(), 'surname' => $faker->lastName(), 'phone' => $faker->e164PhoneNumber(), 'position' => $faker->jobTitle(), 'token' => null, ] } public function anonymizableAttributes(): array { return [ 'email', 'password', 'firstname', 'surname', 'phone', 'position', ] } public function anonymizableDefinition(): array { return [ 'token' => $this->faker->md5(), ] } }
Important note
The data from the
anonymizablemethods on the factory will overwrite the data defined in theanonymizableAttributesmethod on the model!
Running the anonymizer
Anonymization is performed using command:
php artisan db:anonymize
Or on specific models:
php artisan db:anonymize --model=\\App\User --model=\\App\\Profile
License
The MIT License (MIT). Please see License File for more information.
outsidaz/laravel-data-anonymization 适用场景与选型建议
outsidaz/laravel-data-anonymization 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14.47k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2023 年 04 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「anonymization」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 outsidaz/laravel-data-anonymization 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 outsidaz/laravel-data-anonymization 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 outsidaz/laravel-data-anonymization 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Export and import your database tables with fake data
Symfony-based CLI tool for Magento developers
Laravel database export package with profile-based exclusions, anonymization, and zero-impact exports
Pull a sanitized copy of your production database to local/staging environments
Alfabank REST API integration
Declare Model Anonymize Classes To Help Anonymize Data.
统计信息
- 总下载量: 14.47k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-04-14