PHPackages                             philiprehberger/php-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. philiprehberger/php-pipeline

ActiveLibrary

philiprehberger/php-pipeline
============================

Composable pipeline pattern for processing data through ordered stages

v1.1.1(4d ago)11MITPHPPHP ^8.2CI passing

Since Mar 15Pushed 4d agoCompare

[ Source](https://github.com/philiprehberger/php-pipeline)[ Packagist](https://packagist.org/packages/philiprehberger/php-pipeline)[ Docs](https://github.com/philiprehberger/php-pipeline)[ RSS](/packages/philiprehberger-php-pipeline/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (3)Versions (6)Used By (0)

PHP Pipeline
============

[](#php-pipeline)

[![Tests](https://github.com/philiprehberger/php-pipeline/actions/workflows/tests.yml/badge.svg)](https://github.com/philiprehberger/php-pipeline/actions/workflows/tests.yml)[![Latest Version on Packagist](https://camo.githubusercontent.com/b74d918bd62edcfa1d6789a538a8ebe450d26ec80231b02ebf00f08a92b4838c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7068696c69707265686265726765722f7068702d706970656c696e652e737667)](https://packagist.org/packages/philiprehberger/php-pipeline)[![License](https://camo.githubusercontent.com/0eb1ac8856b9885dcb42fad06d757901f5d3179f26eda0f1903eb5e18b200f84/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7068696c69707265686265726765722f7068702d706970656c696e65)](LICENSE)

Composable pipeline pattern for processing data through ordered stages.

---

Requirements
------------

[](#requirements)

DependencyVersionPHP^8.2---

Installation
------------

[](#installation)

```
composer require philiprehberger/php-pipeline
```

---

Usage
-----

[](#usage)

### Basic Pipeline

[](#basic-pipeline)

```
use PhilipRehberger\Pipeline\Pipeline;

$result = Pipeline::send('hello world')
    ->through([
        fn (string $value, \Closure $next) => $next(strtoupper($value)),
        fn (string $value, \Closure $next) => $next(str_replace(' ', '-', $value)),
    ])
    ->thenReturn();

// "HELLO-WORLD"
```

### Class-Based Stages

[](#class-based-stages)

Implement the `Stage` contract for reusable, testable stages:

```
use PhilipRehberger\Pipeline\Contracts\Stage;
use Closure;

class TrimStage implements Stage
{
    public function handle(mixed $passable, Closure $next): mixed
    {
        return $next(trim($passable));
    }
}

$result = Pipeline::send('  hello  ')
    ->pipe(TrimStage::class)
    ->thenReturn();

// "hello"
```

### Conditional Stages

[](#conditional-stages)

```
$isAdmin = true;

$result = Pipeline::send($data)
    ->pipe(ValidateStage::class)
    ->when($isAdmin, AdminEnrichStage::class)
    ->unless($isAdmin, GuestFilterStage::class)
    ->process();
```

### Pipeline Context

[](#pipeline-context)

Share state between stages using `PipelineContext`:

```
use PhilipRehberger\Pipeline\Pipeline;
use PhilipRehberger\Pipeline\PipelineContext;

$context = new PipelineContext();

$result = Pipeline::send($data)
    ->withContext($context)
    ->through([
        function (mixed $value, \Closure $next, PipelineContext $ctx) {
            $ctx->set('started_at', microtime(true));
            return $next($value);
        },
        function (mixed $value, \Closure $next, PipelineContext $ctx) {
            // Access values set by earlier stages
            $started = $ctx->get('started_at');
            return $next($value);
        },
    ])
    ->thenReturn();

// Read context after pipeline completes
$context->all();
```

### Tap

[](#tap)

Add side-effect stages that observe the payload without modifying it:

```
$result = Pipeline::send('hello')
    ->pipe(fn (string $value, \Closure $next) => $next(strtoupper($value)))
    ->tap(function (string $value) {
        logger()->info('After uppercase: ' . $value);
    })
    ->thenReturn();

// "HELLO" — tap does not change the payload
```

### Error Handling

[](#error-handling)

```
$result = Pipeline::send($data)
    ->through([RiskyStage::class])
    ->onFailure(function (\Throwable $e, mixed $passable) {
        return $passable; // Return original data on failure
    })
    ->process();
```

---

API
---

[](#api)

MethodDescription`Pipeline::send(mixed $passable)`Create a new pipeline with the given data`->through(array $stages)`Set the array of stages`->pipe(string|callable $stage)`Append a single stage`->when(bool $condition, string|callable $stage)`Add stage if condition is true`->unless(bool $condition, string|callable $stage)`Add stage if condition is false`->withContext(PipelineContext $context)`Attach shared context passed to stages`->tap(callable $fn)`Add a side-effect stage that does not modify the payload`->onFailure(callable $handler)`Register a failure handler`->process()`Execute the pipeline and return the result`->thenReturn()`Alias for `process()`---

Development
-----------

[](#development)

```
composer install
vendor/bin/phpunit
vendor/bin/pint --test
vendor/bin/phpstan analyse
```

License
-------

[](#license)

MIT

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance99

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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.

###  Release Activity

Cadence

Every ~0 days

Total

5

Last Release

4d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/cfd7d24cbbf32400fa13ce0bbe7a31edd2d66a6d4488eafdb3d64c5337bf0435?d=identicon)[philiprehberger](/maintainers/philiprehberger)

---

Top Contributors

[![philiprehberger](https://avatars.githubusercontent.com/u/8218077?v=4)](https://github.com/philiprehberger "philiprehberger (6 commits)")

---

Tags

phpmiddlewarepipelineChainStages

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[hyperf/hyperf-skeleton

A coroutine framework that focuses on hyperspeed and flexible, specifically use for build microservices and middlewares.

309185.9k](/packages/hyperf-hyperf-skeleton)[hannesvdvreken/guzzle-debugbar

A Guzzle middleware that logs requests to debugbar's timeline

77400.7k1](/packages/hannesvdvreken-guzzle-debugbar)

PHPackages © 2026

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