承接 mhuber84/randomizer 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mhuber84/randomizer

Composer 安装命令:

composer require mhuber84/randomizer

包简介

This TYPO3 extension allows you to randomize the content of database tables, either during a database export or directly in the database. The extension is useful for anonymizing data on or for development systems. The random values are generated with the fakerphp/faker package.

README 文档

README

What does it do?

This extension allows you to randomize the content of database tables, either during a database export or directly in the database.

The extension is useful for anonymizing data on or for development systems. The random values are generated with the fakerphp/faker package.

Randomize in the database

If a field in a table from the mapping contains a value, that value is replaced with a randomly generated one. Empty fields are ignored.

Randomize during export

If a field in a table from the mapping contains a value, that value is replaced with a randomly generated one. By default, only configured tables are exported. However, you can also export the entire database.

Installation

Install the extension by using Composer: composer req mhuber84/randomizer. To use the export feature, install the extension in production. Otherwise, you can add the option --dev to install it on development systems only. The extension is also available in the [TYPO3 Extension Repository] (https://extensions.typo3.org/extension/randomizer/).

Compatibility

RandomizerTYPO3PHP
412 - 138.1 - 8.4
3.511 - 127.4 - 8.3

Configuration

Configure the tables and fields in config/system/additional.php or your site packages ext_localconf.php.

Here is an example configuration for the fe_users table. Available faker providers/formatters are listed at https://fakerphp.github.io/formatters/. An additional Array faker provider is \Mhuber84\Randomizer\FakerProviders\ArrayProvider. It can return a serialzed and json array. It is used for the field 'uc' in this example.

The tables that you want to randomize must have a unique column named uid!

// Database fields to formatter mapping. https://fakerphp.github.io/formatters/
$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['randomizer']['faker.']['mapping.']['fe_users.'] = [
    //TYPO3 Core fields
    'username' => 'userName',
    'password' => 'password',
    'address' => 'streetAddress',
    'telephone' => 'phoneNumber',
    'fax' => 'phoneNumber',
    'email' => 'safeEmail',
    'uc' => 'serialized',
    'zip' => 'postcode',
    'city' => 'city',
    'country' => 'countryCode',
    'www' => 'url',
    'company' => 'company',
    //'image' => '', //TODO
    'first_name' => 'firstName',
    'last_name' => 'lastName',
    'middle_name' => 'firstName',
    'felogin_forgotHash' => 'md5',
];

// List of unique fields. Fields have to be defined in the mapping, too! https://fakerphp.github.io/#modifiers
$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['randomizer']['faker.']['unique.']['fe_users.'] = [
    //TYPO3 Core fields
    'username' => true,
];

// Locale for generated values. https://fakerphp.github.io/#localization
$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['randomizer']['faker.']['locale'] = 'de_DE';

// List of equal fields.
// This has nothing to do with faker, but is useful for fe_users table if username and email are synchronized.
$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['randomizer']['equal.']['fe_users.'] = [
    // The field 'email' gets the value of field 'username'.
    'email' => 'username',
];

// Skip these uids. Do not change them with faker and the equals stuff.
$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['randomizer']['skipUids.']['fe_users'] = [
    // List of uids
    2,
    15,
];

Usage

Randomize in the database

ATTENTION: By default the database changes are not written to the database! If you really want to randomize the values in the database, add the --no-dry-run option.

Run the cli command:

vendor/bin/typo3cms randomizer:randomize

Run vendor/bin/typo3cms randomizer:randomize -h to see all options.

Randomize during export

Run the cli command:

vendor/bin/typo3cms randomizer:export mydatabase.sql

Run vendor/bin/typo3cms randomizer:export -h to see all options.

Custom faker providers

Register your provider in your ext_localconf.php:

$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['randomizer']['faker.']['providers.']['myProvider'] = \Vendor\Namespace\To\MyProvider::class;

Write your provider based on \Faker\Provider\Base. There is an example in \Mhuber84\Randomizer\FakerProviders\ExampleProvider and \Mhuber84\Randomizer\FakerProviders\ArrayProvider. More information on custom providers are available at https://github.com/fzaninotto/Faker#faker-internals-understanding-providers.

Development

Development is done with ddev.

Functional tests

There are two functionial tests for the two commands. You can run them with

ddev functional-tests "^12" "8.2"
ddev functional-tests "^12" "8.3"
ddev functional-tests "^12" "8.4"
ddev functional-tests "^13" "8.2"
ddev functional-tests "^13" "8.3"
ddev functional-tests "^13" "8.4"

Code quality

PHP CS Fixer:

ddev composer require --dev friendsofphp/php-cs-fixer:^3.86
ddev exec .Build/bin/php-cs-fixer fix

Rector & Fractor

Rector:

ddev composer require --dev ssch/typo3-rector:^3.6
ddev exec .Build/bin/rector process

Fractor:

ddev composer require --dev a9f/typo3-fractor:^0.5
ddev exec .Build/bin/fractor process

Credits

Many thanks go out to François Zaninotto and his package fzaninotto/faker!

And also thank you https://github.com/orgs/FakerPHP/people for forking the original package and maintainig it after the original package was archived.

Many thanks for the inspiration to this package go out to Georg Ringer and his package georgringer/gdpr!

Author

Marco Huber, @mhuber84@troet.cafe, mail@marco-huber.de

Feel free to contribute and send in pull requests or create an issue.

mhuber84/randomizer 适用场景与选型建议

mhuber84/randomizer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 27.32k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2020 年 05 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「database」 「faker」 「development」 「typo3」 「Randomize」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 mhuber84/randomizer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mhuber84/randomizer 我们能提供哪些服务?
定制开发 / 二次开发

基于 mhuber84/randomizer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 27.32k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 27
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2020-05-13