gnumast / pipeline
Simple library to send data through a chain of tasks
Installs: 6
Dependents: 0
Suggesters: 0
Security: 0
Stars: 6
Watchers: 0
Forks: 0
pkg:composer/gnumast/pipeline
Requires
- php: >=5.6
This package is not auto-updated.
Last update: 2020-11-27 21:56:53 UTC
README
Pipeline allows to easily chain operations / tasks on the fly or create a reusable chain of commands. Complete documentation is available.
Installation
composer require gnumast/pipeline
Basic usage
Here's a trivial example.
class MakeAllCaps implements TaskInterface { public function run($data) { return mb_strtoupper($data); } } class RemoveAllSpaces implements TaskInterface { public function run($data) { return str_replace(' ', '', $data); } } $pipeline = new Pipeline( new MakeAllCaps(), new RemoveAllSpaces() ); $pipeline->execute("Hello, my name is Steve"); // HELLO,MYNAMEISSTEVE
For simple chains where defining a brand new class isn't really worth it, or if you quickly want to chain things
together, the CallablePipe class wraps anonymous functions to be passed as pipes.
$pipeline = new Pipeline( new CallablePipe(function($data) { return $data * 10; }), new CallablePipe(function($data) { return $data + 50; }) ); $result = $pipeline->execute(10); // 150
You don't have to pass all of your tasks at initialisation time. Pipeline provides an add method to add steps
to an existing object:
$pipeline = new Pipeline(new MakeAllCaps()); $pipeline->add(new RemoveAllSpaces()); $pipeline->execute("Hello, world!"); // HELLO,WORLD!