PHPackages                             smeghead/php-snip-base64-like - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. smeghead/php-snip-base64-like

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

smeghead/php-snip-base64-like
=============================

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

v0.0.0(6mo ago)00MITPHPPHP &gt;=8.3CI passing

Since Oct 31Pushed 6mo agoCompare

[ Source](https://github.com/smeghead/php-snip-base64-like)[ Packagist](https://packagist.org/packages/smeghead/php-snip-base64-like)[ RSS](/packages/smeghead-php-snip-base64-like/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

php-snip-base64-like
====================

[](#php-snip-base64-like)

[![Latest Stable Version](https://camo.githubusercontent.com/e5c1988d12f5f228777252b0b995b5c9cf3086c934a90aaeae1e2896b507c39c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736d6567686561642f7068702d736e69702d6261736536342d6c696b652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/smeghead/php-snip-base64-like)[![Total Downloads](https://camo.githubusercontent.com/a939732530d64778ab60b0f569b40862dfcec1c950989143228c523e1ff6b727/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f736d6567686561642f7068702d736e69702d6261736536342d6c696b652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/smeghead/php-snip-base64-like)[![PHP Version](https://camo.githubusercontent.com/7aa75bb637fa6f5d0e7187145e50620c460440467f50889e92f900d8b9608340/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f736d6567686561642f7068702d736e69702d6261736536342d6c696b652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/smeghead/php-snip-base64-like)

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?
----------------

[](#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
--------

[](#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
------------

[](#installation)

```
composer require smeghead/php-snip-base64-like
```

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

Quick Start
-----------

[](#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
------------------------

[](#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 | preview: ... ]` is emitted automatically with the estimated original size and truncated preview.

Testing
-------

[](#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 &amp; Roadmap
--------------------

[](#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
-------

[](#license)

MIT

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance72

Regular maintenance activity

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

190d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/179acd76bf9ce4197915822481df9901a4f70435e3b2152160b0b227146b9d95?d=identicon)[smeghead](/maintainers/smeghead)

---

Top Contributors

[![smeghead](https://avatars.githubusercontent.com/u/112476?v=4)](https://github.com/smeghead "smeghead (8 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/smeghead-php-snip-base64-like/health.svg)

```
[![Health](https://phpackages.com/badges/smeghead-php-snip-base64-like/health.svg)](https://phpackages.com/packages/smeghead-php-snip-base64-like)
```

###  Alternatives

[bizley/contenttools

ContentTools editor implementation for Yii 2.

8016.7k](/packages/bizley-contenttools)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
