Search by

beebmx / pipeline

beebmx

Pipeline your code

Package info

github.com/beebmx/pipeline

pkg:composer/beebmx/pipeline

Fund package maintenance!

beebmx

Statistics

Installs: 378

Dependents: 1

Suggesters: 0

Stars: 1

Open Issues: 0

1.1.0 2026-11-29 17:04 UTC

This package is auto-updated.

Last update: 2026-11-29 17:05:58 UTC


README

Build Status Total Downloads Latest Stable Version License

Pipeline

Package inspired by Laravel Pipeline, but without Laravel Container

Installation

Install using composer:

composer require beebmx/pipeline

Usage

The basic use of pipeline is:

use Beebmx\Pipeline\Pipeline;

$string = (new Pipeline)
    ->send('say')
    ->through([
        function($string, $next) {
            $string = $string.' hello';

            return $next($string);
        },
        function($string, $next) {
            $string = $string.' world';

            return $next($string);
        }
    ])->execute();

//$string will be 'say hello world'

Important

You should always call the $next callback with the pipe variable as argument for the next pipe or final result.

You can use a class instead of a Closure if that better suits your needs:

use Beebmx\Pipeline\Pipeline;

class MyOwnPipe
{
    public function handle($myPipeObject, Closure $next)
    {
        $myPipeObject->process();
 
        return $next($myPipeObject);
    }
}

$result = (new Pipeline)
    ->send($someObject)
    ->through([
        MyOwnPipe::class,
        OtherPipe::class,
    ])->execute();

Note

By default Pipeline will trigger the handle method.

If you need to change the default handle method in your pipe classes, you can do it like:

use Beebmx\Pipeline\Pipeline;

$result = (new Pipeline)
    ->send($someObject)
    ->via('myOwnMethod')
    ->through([
        MyOwnPipe::class,
        OtherPipe::class,
    ])->execute();

At the end of the pipe's flow, you can finish with the processing like:

use Beebmx\Pipeline\Pipeline;

$string = (new Pipeline)
    ->send('say')
    ->through(function($string, $next) {
        $string = $string.' hello';

        return $next($string);
    })->then(function($string) {
        $string = $string.' world';

        return $string;
    });

//$string will be 'say hello world'

You can add more pipes to the pipeline flow:

use Beebmx\Pipeline\Pipeline;

$string = (new Pipeline)
    ->send('say')
    ->through(function($string, $next) {
        $string = $string.' hello';

        return $next($string);
    })->pipe(function($string, $next) {
        $string = $string.' world';

        return $next($string);
    })->execute();

//$string will be 'say hello world'

Both through and pipe accept an array of pipes or multiple pipes as arguments:

use Beebmx\Pipeline\Pipeline;

$result = (new Pipeline)
    ->send($someObject)
    ->through(MyOwnPipe::class, OtherPipe::class)
    ->execute();

Pipe resolution

Each pipe is resolved in the following order:

  1. Callables (closures, invokable objects, and strings that are callable) are called directly with ($passable, $next).
  2. Strings are treated as a class name (optionally with parameters, like MyOwnPipe::class.':one,two'), instantiated without constructor arguments, and their handle method (or the one set with via) is called.
  3. Objects have their handle method (or the one set with via) called.

Note

Because callables are resolved first, an object with an __invoke method will always be invoked, even if it also has the method set with via.

Warning

A string that matches the name of a PHP function (like 'trim' or 'system') is called as that function, and any other string is instantiated as a class. Never build pipe names from user input.

Testing

composer test

Credits