PHP code example of gandung / pipeline

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

    

gandung / pipeline example snippets


use Gandung\Pipeline\Pipeline;

// Closure based task.
$pipe = (new Pipeline)
	->pipe(function($q) { return $q; })
	->pipe(function($q) { return join(' ', [$q, 'bar']); })
	->pipe(function($q) { return join(' ', [$q, 'baz']); });
$payload = $pipe->invokeAll('foo');

echo sprintf("%s\n", $payload);

use Gandung\Pipeline\Pipeline;
use Gandung\Pipeline\Tests\Fixtures\FooTask;
use Gandung\Pipeline\Tests\Fixtures\BarTask;
use Gandung\Pipeline\Tests\Fixtures\BazTask;

// Instance based task. Class instance must implements __invoke and TaskInterface class interface.
$pipe = (new Pipeline)
	->pipe(new FooTask)
	->pipe(new BarTask)
	->pipe(new BazTask);
$payload = $pipe->invokeAll('foo');

echo sprintf("%s\n", $payload);

use Gandung\Pipeline\PipelineBuilder;

// Closure based task.
$builder = (new PipelineBuilder)
	->add(function($q) { return $q; })
	->add(function($q) { return join(' ', [$q, 'bar']); })
	->add(function($q) { return join(' ', [$q, 'baz']); });
$pipe = $builder->build();
$payload = $pipe->invokeAll('foo');

echo sprintf("%s\n", $payload);

use Gandung\Pipeline\PipelineBuilder;
use Gandung\Pipeline\Tests\Fixtures\FooTask;
use Gandung\Pipeline\Tests\Fixtures\BarTask;
use Gandung\Pipeline\Tests\Fixtures\BazTask;

// Instance based task. Class instance must implements __invoke and TaskInterface class interface.
$builder = (new PipelineBuilder)
	->add(new FooTask)
	->add(new BarTask)
	->add(new BazTask);
$pipe = $builder->build();
$payload = $pipe->invokeAll('foo');

echo sprintf("%s\n", $payload);
__construct($tasks = [], ProcessorInterface $processor = null)
pipe($task)
$task
$task
__construct($routine)
__construct($routine = null)