承接 philiprehberger/php-mask 相关项目开发

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

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

philiprehberger/php-mask

Composer 安装命令:

composer require philiprehberger/php-mask

包简介

Mask sensitive data in strings, arrays, and objects for safe logging

README 文档

README

Tests Latest Version on Packagist Last updated

Mask sensitive data in strings, arrays, and objects for safe logging.

Requirements

  • PHP 8.2+

Installation

composer require philiprehberger/php-mask

Usage

Email masking

use PhilipRehberger\Mask\Mask;

Mask::email('john@example.com');
// "j***@e******.com"

Phone masking

Mask::phone('+1-555-123-4567');
// "+1-555-***-4567"

Credit card masking

Mask::creditCard('4111 1234 5678 1111');
// "4111 **** **** 1111"

IP address masking

Mask::ip('192.168.1.100');
// "192.168.*.*"

IBAN masking

Mask::iban('DE89370400440532013000');
// "DE****************3000"

Mask::iban('GB29NWBK60161331926789', '#');
// "GB################6789"

Custom masking

Mask::custom('SensitiveData', visibleStart: 3, visibleEnd: 3);
// "Sen*******ata"

Mask::custom('SensitiveData', visibleStart: 0, visibleEnd: 0);
// "*************"

URL masking

Mask::url('https://user:pass@example.com/path?token=abc123&key=secret');
// "https://u***:p***@example.com/path?token=a*****&key=s*****"

Mask::url('https://example.com/search?q=test');
// "https://example.com/search?q=t***"

JWT masking

Mask::jwt('eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0.SflKxwRJSMeKKF2QT4fwpM');
// "eyJhbGciOiJIUzI1NiJ9.[MASKED].[MASKED]"

Generic string masking

Mask::string('SensitiveData');
// "Se*********ta"

Mask::string('SensitiveData', visibleStart: 3, visibleEnd: 3);
// "Sen*******ata"

Recursive array masking with dot notation

$data = [
    'user' => [
        'name' => 'John',
        'address' => [
            'street' => '123 Main St',
        ],
    ],
    'password' => 'secret123',
];

Mask::arrayRecursive($data, ['password', 'user.address.street']);
// ['user' => ['name' => 'John', 'address' => ['street' => '12*******St']], 'password' => 'se*****23']

Array masking (deep)

$data = [
    'name' => 'John',
    'email' => 'john@example.com',
    'nested' => [
        'ssn' => '123-45-6789',
    ],
];

Mask::array($data, ['email', 'ssn']);
// ['name' => 'John', 'email' => 'jo************om', 'nested' => ['ssn' => '12*******89']]

JSON masking

$json = '{"name":"John","ssn":"123-45-6789"}';

Mask::json($json, ['ssn']);
// '{"name":"John","ssn":"12*******89"}'

Redaction policies

use PhilipRehberger\Mask\RedactionPolicy;

$policy = RedactionPolicy::create()
    ->maskField('user.email', 'email')
    ->maskField('*.secret', 'full')
    ->maskPattern('/password|token/i', 'full');

$data = [
    'user' => ['name' => 'John', 'email' => 'john@example.com'],
    'service' => ['secret' => 'sk-12345'],
    'password' => 'hunter2',
];

$result = $policy->apply($data);
// ['user' => ['name' => 'John', 'email' => 'j***@e******.com'],
//  'service' => ['secret' => '********'],
//  'password' => '*******']

Custom configuration

use PhilipRehberger\Mask\MaskConfig;

Mask::configure(new MaskConfig(
    maskChar: '#',
    preserveLength: false,
    visibleStart: 3,
    visibleEnd: 3,
));

Mask::string('SensitiveData');
// "Sen###ata"

API

Method Description
Mask::email(string $email): string Mask an email address, preserving first char of local/domain and TLD
Mask::phone(string $phone): string Mask a phone number, preserving country code and last 4 digits
Mask::creditCard(string $number): string Mask a credit card, showing first 4 and last 4 digits
Mask::ip(string $ip): string Mask an IP address, showing first two octets (v4) or groups (v6)
Mask::iban(string $value, string $char = '*'): string Mask an IBAN, showing country code and last 4 characters
Mask::custom(string $value, int $visibleStart, int $visibleEnd, string $char = '*'): string Mask a string with configurable visible start/end lengths
Mask::url(string $url): string Mask URL query parameter values and embedded credentials
Mask::jwt(string $token): string Mask JWT payload and signature, preserving header
Mask::string(string $value, int $visibleStart = 2, int $visibleEnd = 2): string Mask a generic string with configurable visible characters
Mask::arrayRecursive(array $data, array $keys, string $char = '*'): array Recursively mask values at specified keys, supporting dot notation paths
Mask::array(array $data, array $keys): array Deep-mask specified keys in an associative array
Mask::json(string $json, array $keys): string Parse JSON, mask specified keys, re-encode
Mask::configure(MaskConfig $config): void Set global masking configuration
Mask::resetConfig(): void Reset configuration to defaults
RedactionPolicy::create(): self Create a new redaction policy
RedactionPolicy::maskField(string $path, string $method): self Register a masking rule for a field path (dot notation, wildcards)
RedactionPolicy::maskPattern(string $regex, string $method): self Register a pattern-based rule matched against field names
RedactionPolicy::apply(array $data): array Apply all rules to an array, returning masked copy
RedactionPolicy::merge(self $other): self Merge another policy into this one

Development

composer install
vendor/bin/phpunit
vendor/bin/pint --test
vendor/bin/phpstan analyse

Support

If you find this project useful:

Star the repo

🐛 Report issues

💡 Suggest features

❤️ Sponsor development

🌐 All Open Source Projects

💻 GitHub Profile

🔗 LinkedIn Profile

License

MIT

philiprehberger/php-mask 适用场景与选型建议

philiprehberger/php-mask 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 58 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 03 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 philiprehberger/php-mask 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-15