petrknap / external-filter
Library for easier work with external filters
Fund package maintenance!
Other
Requires
- php: >=8.1
- symfony/process: ^4.0|^5.0|^6.0|^7.0
Requires (Dev)
- nunomaduro/phpinsights: ^2.11
- petrknap/profiler: ^2.2
- petrknap/shorts: ^3.0
- phpstan/phpstan: ^1.12
- phpunit/phpunit: ^10.5
- squizlabs/php_codesniffer: ^3.7
README
Encapsulation of a command along with its options which provides a filter method. Its primary role is to facilitate filtering operations within a pipeline, allowing for easy chaining and execution of executable filters.
use PetrKnap\ExternalFilter\Filter; # echo "H4sIAAAAAAAAA0tJLEkEAGPz860EAAAA" | base64 --decode | gzip --decompress echo Filter::new('base64', ['--decode']) ->pipe(Filter::new('gzip', ['--decompress'])) ->filter('H4sIAAAAAAAAA0tJLEkEAGPz860EAAAA');
If you want to process external data, redirect output or get errors, you can use input, output or error streams.
use PetrKnap\ExternalFilter\Filter; $errorStream = fopen('php://memory', 'w+'); Filter::new('php')->filter( '<?php fputs(fopen("php://stderr", "w"), "error");', error: $errorStream, ); rewind($errorStream); echo stream_get_contents($errorStream); fclose($errorStream);
If you want to call PHP code in the pipeline, you can via factory.
use PetrKnap\ExternalFilter\Filter; echo Filter::new(phpSnippet: 'fputs(STDOUT, fgets(STDIN));') ->filter(b'data');
Run composer require petrknap/external-filter
to install it.
You can support this project via donation.
The project is licensed under the terms of the LGPL-3.0-or-later
.