oihana/php-masking
Composer 安装命令:
composer require oihana/php-masking
包简介
Lightweight, framework-agnostic PHP data-masking toolkit: anonymize and redact document fields with composable maskers (email, phone, credit card, dates, ZIP, decimals, X-ify…) for dumps, fixtures and test data.
关键字:
README 文档
README
A lightweight, framework-agnostic PHP toolkit to anonymize and redact the fields of your documents.
📚 Documentation
User guides (FR + EN), with narrative explanations, examples and recipes:
| 🇬🇧 English documentation | 🇫🇷 Documentation française |
| Getting started, the masking rules, the maskers catalogue, testing. | Démarrage, les règles de masquage, le catalogue des maskers, tests. |
Auto-generated API reference (phpDocumentor):
👉 https://bcommebois.github.io/oihana-php-masking
🚀 Features
- 🎭 10 composable maskers —
email,phone,creditCard(Luhn-valid),datetime,decimal,integer,zip,random,randomString,xifyFront. - 🗂️ Document engine — apply a list of path-based rules to a whole document, descending into nested objects and arrays.
- 🧭 Expressive path DSL — target a leaf by name, exact dotted path, name-at-any-depth (
.name), wildcard (*) or a backtick-quoted literal key. - 🛡️ Identity-safe, your way — pass the attributes to protect from masking; fully data-store agnostic (no field name is hardcoded).
- 🧱 Standalone functions, no framework — autoloaded via
composer.autoload.files, strongly-typed enums instead of magic strings. - 🧪 100% unit-tested.
💡 Designed to be lightweight, testable and compatible with any PHP 8.4+ project — dumps, fixtures, test data, GDPR/PII redaction.
📦 Installation
Requires PHP 8.4+
Install via Composer:
composer require oihana/php-masking
⚡ Quick start
<?php require __DIR__ . '/vendor/autoload.php'; use function oihana\masking\maskDocument; $document = [ '_key' => '42', 'name' => 'Jane Doe', 'email' => 'jane.doe@example.com', 'phone' => '+33 6 12 34 56 78', 'profile' => [ 'address' => '221B Baker Street', 'zip' => '75001', ], ]; $rules = [ [ 'path' => 'name' , 'type' => 'xifyFront' , 'unmaskedLength' => 2 ], [ 'path' => 'email' , 'type' => 'email' ], [ 'path' => 'phone' , 'type' => 'phone' ], [ 'path' => 'profile.zip' , 'type' => 'zip' ], [ 'path' => '.address' , 'type' => 'randomString' ], ]; // The 3rd argument lists the attributes to keep, so `_key` survives. // By default nothing is protected (the engine is data-store agnostic). $masked = maskDocument( $document , $rules , [ '_key' ] ); // _key stays '42'; name -> "xxxx xxe", email -> "aZ12.bY34@cX56.invalid", etc.
Need a single value rather than a whole document? Use the dispatcher:
use function oihana\masking\maskValue; maskValue( 'email' , 'real@example.com' ); // "x7Bq.9aMz@Kp3R.invalid" maskValue( 'xifyFront' , 'secret' , [ 'unmaskedLength' => 3 ] ); // "xxxret"
✅ Tests & coverage
Run the full unit-test suite (PHPUnit, strict mode):
composer test
Run a single test case:
./vendor/bin/phpunit --filter MaskingsTest
Measure coverage (requires Xdebug or PCOV):
composer coverage # text + Clover + HTML under build/coverage/ composer coverage:md # readable Markdown summary (build/coverage/COVERAGE.md)
The suite covers 100% of lines. For the testing philosophy and the
@codeCoverageIgnore policy, see the detailed guide:
wiki/en/testing.md · wiki/fr/testing.md.
🧾 License
This project is licensed under the Mozilla Public License 2.0 (MPL-2.0).
👤 About the author
- Author : Marc ALCARAZ (aka eKameleon)
- Mail : marc@ooop.fr
- Website : http://www.ooop.fr
🛠️ Generate the documentation
We use phpDocumentor to generate the API reference into the ./docs folder:
composer doc
🔗 Related packages
oihana/php-reflect– reflection and hydration utilities (provides theConstantsTraitused by the enums):https://github.com/BcommeBois/oihana-php-reflectoihana/php-arango– ArangoDB toolkit; the original home of this masking engine, now consumingoihana/php-masking:https://github.com/BcommeBois/oihana-php-arango
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MPL-2.0
- 更新时间: 2026-06-14
