PHP code example of warmans / pipeline

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

    

warmans / pipeline example snippets



use Pipeline\Pipeline;
use Pipeline\Workload;
use Pipeline\Workload\Task;
use Pipeline\Stage\CallbackStage;

//setup two tasks
$workload = new Workload();
$workload->addTask(new Workload\Task('foo'));
$workload->addTask(new Workload\Task('bar'));

//setup a pipeline
$pipeline = new Pipeline();

//setup two stages
$pipeline->addStage(new CallbackStage('first-stage', function (Task $task) {
    $task->setMeta('done-first', true);
}));
$pipeline->addStage(new CallbackStage('second-stage', function (Task $task) {
    $task->setMeta('done-second', true);
}));

//setup the context to enable logging
$context = new Context();
$context->setLogger(function($msg, $writeLn=true) {
    echo $msg . ($writeLn ? "\n" : "");
});

//execute
$pipeline->execute($workload, $context);

var_dump($workload);