ztsu/pipe

Pipeline pattern simple implementation

Maintainers

Details

github.com/ztsu/pipe

Source

Issues

Installs: 898

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/ztsu/pipe

1.0.0 2016-08-02 17:17 UTC

This package is not auto-updated.

Last update: 2025-10-12 00:57:29 UTC


README

Provides a simple implemenation of a pipeline pattern.

Requirements

Supports PHP starting with version 5.4.

Installation

composer require ztsu/pipe

Usage

Here is a basic usage example:

use Ztsu\Pipe\Pipeline;

$a = function ($payload, $next) {
    return $next($payload . "a");
};

$b = function ($payload, $next) {
    return $next($payload . "b");
};

$pipeline = new Pipeline;

$pipeline->add($a);
$pipeline->add($b);

echo $pipeline->run(""); // "ab"

Here $a and $b are callables with two arguments. First is for accumulating a payload from previous stages. Second is for continuing next stages in a pipeline.

For break pipeline just return $payload instead of call $next:

$pipeline = new Pipeline;

$break = function ($payload, $next) {
    return $payload;
};

$pipeline->add($a);
$pipeline->add($break);
$pipeline->add($b);

echo $pipeline(""); // "a"

A pipeline is callable too. And it's able to use as a stage.

For this just add it to another pipeline:

$pipeline = new Pipeline;

$pipeline->add($a);
$pipeline->add($bc);

echo $pipeline(""); // "abc"

If use pipeline with a break as a stage it breaks entire pipeline.

License

MIT.