PHP code example of ztsu / pipe

1. Go to this page and download the library: Download ztsu/pipe library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ztsu / pipe example snippets



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"

$pipeline = new Pipeline;

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

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

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

$pipeline = new Pipeline;

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

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