kennedytedesco/simple-stream-filter

Painless stream filtering in PHP.

0.3 2019-08-26 01:03 UTC

This package is auto-updated.

Last update: 2024-03-27 03:18:44 UTC


README

Painless stream filtering in PHP. The Stream Filter API it's a bit obscure. What about making a custom filter using just an anonymous function?

Example:

<?php

use KennedyTedesco\SimpleStreamFilter\Filter;

$stream = \fopen('file.txt', 'rb');

Filter::append($stream, static function ($chunk = null) {
    return \strip_tags($chunk);
});

\fpassthru($stream);

\fclose($stream);

Or, if you want to:

<?php

use KennedyTedesco\SimpleStreamFilter\Filter;

final class StripTagsFilter
{
    public function __invoke($chunk)
    {
        return \strip_tags($chunk);
    }
}

$stream = \fopen('file.txt', 'rb');

Filter::append($stream, new StripTagsFilter);

\fpassthru($stream);

\fclose($stream);

Install

PHP 7.2 or greater required.

$ composer require kennedytedesco/simple-stream-filter

Credits

This project is like a lightweight version of the awesome php-stream-filter.