opxcore/pipeline

The OpxCore pipeline.

1.0.0 2021-03-03 14:34 UTC

This package is auto-updated.

Last update: 2024-11-29 06:35:36 UTC


README

Build Status Coverage Status Latest Stable Version Total Downloads License

Pipeline is a class designed to perform chained modifications.

Pipe

"Pipe" is a class performing some transformations to passed value.

class Pipe
{
    public function handle($passable, callable $next)
    {
        // here you can perform modifications of passable 
        
        // and pass it to next pipe
        $modified = $next($passable);
        
        // and finally you can modify returned value here 
        
        return $modified;
    }
}

Calling $next() function runs next modifications. You can break modification chain by returning desired result without calling this function.

Usage

use OpxCore\Container\Container;
use OpxCore\Pipeline\Pipeline;

$container = new Container;
$pipeline = new Pipeline($container);

$result = $pipeline
    ->send('some value')
    ->through(['pipe_1', 'pipe_2'])
    ->via('handle')
    ->then(function ($passable){
        return $passable;
    })
    ->run();

This will pass value through 'pipe_1', 'pipe_2', then modified value would be passed to callback and returned same way.

Pipes may be class names, so container must be set to resolve and make them (with all needed dependencies). Other way you can pass already created classes, so this way you do not need container.