PHP code example of ledc / pipeline

1. Go to this page and download the library: Download ledc/pipeline 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/ */

    

ledc / pipeline example snippets



use Ledc\Pipeline\Pipeline;

//初始数据
class Request
{
    public int $number = 1;
}

//管道数组
$pipes = [];
foreach (range(1, 3) as $row) {
    $pipes[] = function ($request, $next) use ($row) {
        echo 'pipe-before' . $row . PHP_EOL;
        $request->number += $row;
        $request = $next($request);
        echo 'pipe-after' . $row . PHP_EOL;
        return $request;
    };
}

//核心逻辑
$init = function ($request) {
    echo 'init start' . PHP_EOL;
    var_dump($request);
    echo 'init end' . PHP_EOL;
    return 'init';
};

$pipeline = new Pipeline();
$result = $pipeline->send(new Request())
    ->through($pipes)
    ->then($init);

var_dump($result);