clue/stream-filter
Lightweight PHP library that simplifies stream filtering with a few helper functions (append, prepend, fun, remove). Easily apply built-in or custom stream filters for on-the-fly transformations like gzip, encoding conversion, and compression, with solid tests and SOLID design.
Start by installing via Composer:
composer require clue/stream-filter
Then import the functions:
use function Clue\StreamFilter\append;
use function Clue\StreamFilter\fun;
use function Clue\StreamFilter\remove;
The most common first use case is applying simple transformations to streams — e.g., converting text to uppercase on write:
$stream = fopen('php://temp', 'r+');
append($stream, 'strtoupper');
fwrite($stream, 'hello'); // writes "HELLO" to the stream
rewind($stream);
echo stream_get_contents($stream); // "HELLO"
append() or prepend() to inject callbacks on existing streams (e.g., file, socket, php://output) for on-the-fly encoding/decoding, logging, or validation. Separate STREAM_FILTER_READ and STREAM_FILTER_WRITE modes for bidirectional control.fun() to wrap built-in filters (zlib.deflate, string.rot13, convert.base64-encode, string.strip_tags) as pure callable functions for non-stream operations:
$encode = fun('convert.base64-encode');
echo $encode('data'); // 'ZGF0YQ=='
append()/prepend() and pass them to remove() to cleanly detach filters before closing streams (especially important when reusing streams or debugging).$chunk = null signature in callbacks for append()/prepend() to handle final flushes (e.g., closing gzip output, finalizing compression).stream_select() incompatibility: Once any filter is attached via this package, the stream can no longer be used with stream_select(). Workaround: perform stream_select() on the unfiltered resource and pipe data through fun() manually.E_USER_WARNING — use try/catch around stream operations or custom error handlers for debugging.null as a filter parameter explicitly (e.g., fun('filter', null)) may cause issues; omit the parameter entirely if the filter doesn’t require it (fixed in v1.4.0+).$callback(null) flushing signature in PHP < 5.4. Tests confirm PHP 5.3–8.3 compatibility, but prefer modern PHP.fun() uses an internal temp stream — close filters by invoking them with no arguments ($fun()) once done to avoid leaks (especially critical for compression filters).Clue\StreamFilter\, not a class — ensure your use statements include function, not class.How can I help you explore Laravel packages today?