定制 smeghead/php-snip-base64-like 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

smeghead/php-snip-base64-like

Composer 安装命令:

composer require smeghead/php-snip-base64-like

包简介

A PHP library to snip base64-like strings and prevent log bloating.

README 文档

README

Latest Stable Version Total Downloads PHP Version

A PHP helper that trims base64-like blobs out of log messages so your log files stay readable and small while still recording the contextual data you need.

Why Snip Base64?

In one of our production projects we forward detailed API interaction logs to operations. Some endpoints embed files as base64 strings inside JSON payloads; keeping those payloads verbatim caused the log volume to explode. Completely discarding the payload was not an option—we still needed an audit trail. This library strikes the balance by detecting base64-like strings, recording their presence, and replacing the verbose payload with a concise placeholder.

Features

  • Detects base64-like text using configurable length thresholds and alphabet heuristics.
  • Replaces oversized segments with a compact summary that records the original byte size and a short preview.
  • Supports both raw strings and structured payloads (arrays, JsonSerializable, objects implementing __toString()).
  • Keeps the surrounding JSON or log structure intact so downstream tooling still works.

Installation

composer require smeghead/php-snip-base64-like

The package provides an autoloadable Smeghead\SnipBase64Like\Snipper class.

Quick Start

use Smeghead\SnipBase64Like\Snipper;

$snipper = new Snipper(
    minLength: 256,            // base64 strings shorter than this are kept
    previewLength: 100         // keep 100 leading characters from the base64 blob
);

$logPayload = [
	'endpoint' => '/v1/upload',
	'requestId' => 'req-12345',
	'payload' => [
		'metadata' => ['filename' => 'report.pdf'],
		'file' => $veryLargeBase64String,
	],
];

$sanitized = $snipper->snip($logPayload);

echo json_encode($sanitized, JSON_PRETTY_PRINT);
/*
{
	"endpoint": "/v1/upload",
	"requestId": "req-12345",
	"payload": {
		"metadata": {
			"filename": "report.pdf"
		},
		"file": "[base64 payload ~42816 bytes | preview: JVBERi0xLjQKJc... ]"
	}
}
*/

Pass strings, arrays, or objects—snip() will walk the structure and redact any values that look like oversized base64 blocks.

Configuration Highlights

  • minLength: Minimum character count that triggers redaction. Tune this to your payload sizes.
  • previewLength: Number of leading characters preserved in the placeholder (defaults to 100 so you retain enough context to recognise the payload while keeping logs lean).
  • Placeholder format: [base64 payload ~<bytes> bytes | preview: <prefix>... ] is emitted automatically with the estimated original size and truncated preview.

Testing

Run the PHPUnit suite after making changes:

composer test

PHPUnit uses the project’s phpunit.xml bootstrap to load Composer autoloading and the tests/ directory.

Status & Roadmap

  • Implement recursive snipping logic with streaming-safe heuristics.
  • Add JSON Path helper to target only selected fields.
  • Provide PSR-3 processor middleware for Monolog.
  • Document strategies for masking secrets alongside base64 data.

Contributions are welcome—open an issue or submit a pull request to discuss new ideas.

License

MIT

smeghead/php-snip-base64-like 适用场景与选型建议

smeghead/php-snip-base64-like 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 10 月 31 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 smeghead/php-snip-base64-like 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-10-31