solitus0/payload-path-sanitizer
Composer 安装命令:
composer require solitus0/payload-path-sanitizer
包简介
Stand-alone recursive payload sanitizer with matcher-based targeting and pluggable value sanitizers.
关键字:
README 文档
README
solitus0/payload-path-sanitizer is a minimal PHP 8.1+ library for redacting or masking values deep inside associative payloads before they leave your system (logging, telemetry, queues, etc.). Define rules that pair a matcher (decides where) with a value sanitizer (decides how), then run the sanitizer to get a safe copy of the original payload.
Installation
composer require solitus0/payload-path-sanitizer
Core Concepts
- Rule – pairs a
Matcherand aValueSanitizer. - SanitizerContext – convenient builder/iterator for rules (you can also pass any
iterable<Rule>). - Sanitizer – walks the payload depth-first and replaces leaf values whenever a rule's matcher returns
true.
Quick Start
use Solitus0\PayloadSanitizer\{Rule, SanitizerContext, Sanitizer}; use Solitus0\PayloadSanitizer\Matcher\KeyMatcher; use Solitus0\PayloadSanitizer\ValueSanitizer\SimpleValueSanitizer; $context = new SanitizerContext( new Rule(new KeyMatcher('password'), new SimpleValueSanitizer()), ); $sanitized = (new Sanitizer())->sanitize($payload, $context);
SimpleValueSanitizer replaces the value with a SANITIZED (...) marker, but you will usually create your own value sanitizer (see below).
Custom Matchers
Implement Solitus0\PayloadSanitizer\Matcher\SanitizerMatcherInterface and inspect the current leaf:
final class EndsWithIdMatcher implements SanitizerMatcherInterface { public function matches($key, array $path, $value = null): bool { return str_ends_with((string) $key, '_id'); } }
Available built-ins:
KeyMatcher– matches an exact key.ParentKeyMatcher– matches by parent key (useful for targeting nested structures).PathContainsMatcher– ensures the traversal path contains a set of keys (order agnostic).
Combine matchers by writing your own composite if needed.
Custom Value Sanitizers
Implement Solitus0\PayloadSanitizer\ValueSanitizer\ValueSanitizerInterface and transform the matched value into whatever should be persisted/logged. Typical strategies include fixed strings, hashes, or length-prefixed tokens.
final class FixedMaskSanitizer implements ValueSanitizerInterface { public function sanitize($value): string { return '***'; } }
Advanced Usage
- Dynamic rule sets – since
Sanitizer::sanitizeaccepts anyiterable<Rule>, you can yield rules lazily or build them per request. - Immutable pipelines – rules are evaluated in the order provided; the first matching rule wins for each payload leaf, ensuring deterministic behavior.
- Binary-safe – matchers receive the raw value, so you can restrict sanitation to certain types before falling back to generic fallbacks.
Testing Tips
- Assert on the sanitized payload rather than internal behavior.
- Provide representative payload fixtures (arrays with strings, ints, and nested arrays) to ensure matchers behave as expected.
License
MIT
solitus0/payload-path-sanitizer 适用场景与选型建议
solitus0/payload-path-sanitizer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 12 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「sanitizer」 「payload」 「Masking」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 solitus0/payload-path-sanitizer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 solitus0/payload-path-sanitizer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 solitus0/payload-path-sanitizer 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Runn Me! Validation and Sanitization Library
Laravel Profanity Filter - Powerful PHP package for detecting, filtering, and masking profanity in multiple languages. Supports leet speak, custom word lists, case sensitivity, and seamless Laravel integration.
Data sanitizer forked from Waavi/Sanitaize with support for Laravel 5 to 8. .
😷 Sanitize your objects with attributes.
Payload PHP Library
Modern PHP Sanitization Library
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 30
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-15