PHPackages                             baron/pipeline - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. baron/pipeline

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

baron/pipeline
==============

Recursive Pipeline Construct

05PHP

Since Mar 19Pushed 2y agoCompare

[ Source](https://github.com/marek-baron/pipeline)[ Packagist](https://packagist.org/packages/baron/pipeline)[ RSS](/packages/baron-pipeline/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Simple Recursive Pipeline with few dependencies
===============================================

[](#simple-recursive-pipeline-with-few-dependencies)

With this lib, we are able to separate long executions into multiple tasks. A pipeline enables you to better fulfill single responsibility requirements. This results in better maintainability and testability.

### How to

[](#how-to)

- The Pipeline passes the Payload and its self into the task.

`public function __invoke(PayloadInterface $payload, PipelineInterface $pipeline): PayloadInterface;`

- The first task calls the next task, calls the next task, calls the next task ...

`$payloadAfterAllSteps = $pipeline->handle($payload);`

- Like in PSR-7 (the request object) you are now able to handle all information by adding and getting information from a payload object

```
$value = $genericPayload->getValue();
$value++;
$genericPayload->setValue($value);

```

##### Step-by-Step

[](#step-by-step)

1. Create Task(s)
2. Initialize Pipeline
3. Fill Payload
4. Execute Pipe
5. Evaluate Pipe

### Use Pipeline Service

[](#use-pipeline-service)

You are able to simple create your pipelines from your DI (PSR-11 Container Service Manager required). It just takes two lines of code (+Config)

The `PipelineService` class allows you to pass tasks as service hashes.

```
// .. In your factory
$tasksFromEnvConfig = $config->getTasks() // somewhere in your config: [Task1::class, Task2::class, Task3::class];
$pipeline = (new PipelineService)->createPsr11($serviceManager, $tasksFromEnvConfig);
```

With mbaron/Pipeline you are able to create quite complex tasks in no time:

```
// Configuration of BiPRO Request (= German XML Request Standard)
$tasklist = [
    CheckServiceAvailabilityTask::class,
    [ // do Request
        ErrorHandlerTask::class, // catch execution of submission even on error
        [
            PrepareDataTask::class,
            ValidateDataTask::class,
            DoGetOfferRequestTask::class
        ],
        // .. some additional things like set quote, upload documents etc.
    ],
    [ // do something additionally
        LogResultLocalyTask::class,
        LogResultInDWTask::class,
    ]
];
```

### Best Practices

[](#best-practices)

- Use `RecursivePipeline` to create "Sub Pipelines" =&gt; Dynamic Tasks
- Because of the Structure every task has a "before handle next step" and "after handle next step"
- Interrupt pipeline by throwing an exception or return $payload without handling the next step

### Examples

[](#examples)

##### Initialize Pipeline manually

[](#initialize-pipeline-manually)

Of course it would be better to use DI instead of `new` all the time

```
// Create Tasks in order of execution
$tasks = [
    new ExceptionTask(),
    new ErrorBagTask(),
    new OpenStreamTask(),
    new ReadValuesTask(),
    new ValidateValuesTask(),
    new RequireDocumentsTask(),
    new HandleImportTask(),
];

// Create Pipeline
$pipeline = new \mbaron\Pipeline\Pipeline($tasks);

// Create Payload
$payload = new ImportPayload();

// Setup Payload
$payload->setEnvironment($env); // setOptions(...)
$payload->setConfig($config);

// Do the thing the pipeline is constructed for
$payload = $pipeline->handle($payload);
// Evaluate result
$payload->getMessage();
```

##### Simple Task which does something

[](#simple-task-which-does-something)

Use the pipeline object to pass configuration and handle data between tasks

```
public function __invoke(PayloadInterface $payload, PipelineInterface $pipeline): PayloadInterface {
    // there is something, so we need to continue with our tasks
    if ($payload->getValue() > 0) {
        return $pipeline->handle($payload);
    }

    // we do not allow negative values => Completely interrupt process
    if ($payload->getValue() < 0) {
        throw new \Exception("Negative Values are not allowed here");
    }

    // Value is 0, let's pretend there is nothing more to do. => Interrupt from here and go back up the callstack
    return $payload;
}
```

##### Exception Handling Task

[](#exception-handling-task)

Handle (maybe only certain) exceptions within the pipe

```
public function __invoke(PayloadInterface $payload, PipelineInterface $pipeline): PayloadInterface {
    try {
        // handle next steps BEFORE doing something
        $payload = $pipeline->handle($payload);
    } catch (\Throwable $e) {
        $this->logger->logException($e, ['context' => $payload]);
    }
    return $payload;
}
```

##### Error Bag

[](#error-bag)

Process multiple errors with error bags

```
public function __invoke(PayloadInterface $payload, PipelineInterface $pipeline): PayloadInterface {
    // Do something before handle next steps
    $payload->setErrorBag($this->errorBag);

    // Pipeline will add errors to error bag
    $payload = $pipeline->handle($payload);

    // "On the way back" and after handling, we check if something is inside the error bag
    if ($payload->getErrorBag()->hasErrors()) {
        $payload->setMessage($payload->getErrorBag()->toString());
    }

    return $payload;
}
```

###  Health Score

13

—

LowBetter than 1% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity19

Early-stage or recently created project

 Bus Factor1

Top contributor holds 66.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/cac6562d9d5c42c1dbc5c69fcf68367441f14389bc118f0cc2be1c9e02a4b9f8?d=identicon)[marek-baron](/maintainers/marek-baron)

---

Top Contributors

[![teewurst](https://avatars.githubusercontent.com/u/7197260?v=4)](https://github.com/teewurst "teewurst (2 commits)")[![marek-baron](https://avatars.githubusercontent.com/u/47612293?v=4)](https://github.com/marek-baron "marek-baron (1 commits)")

### Embed Badge

![Health badge](/badges/baron-pipeline/health.svg)

```
[![Health](https://phpackages.com/badges/baron-pipeline/health.svg)](https://phpackages.com/packages/baron-pipeline)
```

###  Alternatives

[norcross/airplane-mode

Disables external data calls and loading for working on a purely local (i.e. no internet connection) WordPress site

4766.6k1](/packages/norcross-airplane-mode)[algb12/graph-ds

A fast implementation of the graph data-structure in PHP

81132.4k1](/packages/algb12-graph-ds)[fig/event-dispatcher-util

Useful utility classes and traits for implementing the PSR events standard

27423.2k19](/packages/fig-event-dispatcher-util)[codelytv/coding-style

PHP Coding Style rules we use in Codely

5633.5k8](/packages/codelytv-coding-style)[sciphp/numphp

PHP library for scientific computing.

6618.9k](/packages/sciphp-numphp)[sssurii/laravel-ics

Laravel package to create iCalendar / ICS files. Send new event invitations via Email and can cancel or update already sent invitation.

2159.3k](/packages/sssurii-laravel-ics)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
