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

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

league/pipeline
===============

A plug and play pipeline implementation.

1.1.0(1y ago)1.0k16.0M—5.1%74[3 issues](https://github.com/thephpleague/pipeline/issues)[1 PRs](https://github.com/thephpleague/pipeline/pulls)20MITPHPPHP ^8.0CI passing

Since Jun 25Pushed 1y ago31 watchersCompare

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

READMEChangelogDependencies (1)Versions (9)Used By (20)

League\\Pipeline
================

[](#leaguepipeline)

[![Author](https://camo.githubusercontent.com/b9e526851cdefc2067ee75a43fd0c07644f5b9a88111e7ca05e6457f906524a4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f617574686f722d406672616e6b64656a6f6e67652d626c75652e7376673f7374796c653d666c61742d737175617265)](https://twitter.com/frankdejonge)[![Maintainer](https://camo.githubusercontent.com/0a86726656a3517d804f2fdbd4fd0219607a947b5a8c9292de30046a209fdd49/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6d61696e7461696e65722d40736861646f7768616e642d626c75652e7376673f7374796c653d666c61742d737175617265)](https://twitter.com/shadowhand)[![Build Status](https://camo.githubusercontent.com/033e4c71cd28b3f08bf001115881da6af738a0fd8924a737fbff0e5a1f4b0d41/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7468657068706c65616775652f706970656c696e652f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/thephpleague/pipeline)[![Coverage Status](https://camo.githubusercontent.com/8932497a97e85c1dd2b9d9a85f1a66ffb1fa812d4f464a95dbcbf2218190bd9d/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f7468657068706c65616775652f706970656c696e652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/thephpleague/pipeline/code-structure)[![Quality Score](https://camo.githubusercontent.com/61526c6cad4ac927034d0bc6b39cfebf44cf0cd050a9e5643bc614597a031126/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7468657068706c65616775652f706970656c696e652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/thephpleague/pipeline)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Packagist Version](https://camo.githubusercontent.com/9063634e05fe92ce84733af0fd671a336dff9bfd076963070c40e546867c4aff/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c65616775652f706970656c696e652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/league/pipeline)[![Total Downloads](https://camo.githubusercontent.com/87eaec5422a6050ea98f7bbf3b242e6410ed3547ee420affa3c8ff0b0f222eed/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c65616775652f706970656c696e652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/league/pipeline)

This package provides a pipeline pattern implementation.

Pipeline Pattern
----------------

[](#pipeline-pattern)

The pipeline pattern allows you to easily compose sequential stages by chaining stages.

In this particular implementation the interface consists of two parts:

- StageInterface
- PipelineInterface

A pipeline consists of zero, one, or multiple stages. A pipeline can process a payload. During the processing the payload will be passed to the first stage. From that moment on the resulting value is passed on from stage to stage.

In the simplest form, the execution chain can be represented as a foreach:

```
$result = $payload;

foreach ($stages as $stage) {
    $result = $stage($result);
}

return $result;
```

Effectively this is the same as:

```
$result = $stage3($stage2($stage1($payload)));
```

Immutability
------------

[](#immutability)

Pipelines are implemented as immutable stage chains. When you pipe a new stage, a new pipeline will be created with the added stage. This makes pipelines easy to reuse, and minimizes side-effects.

Usage
-----

[](#usage)

Operations in a pipeline, stages, can be anything that satisfies the `callable`type-hint. So closures and anything that's invokable is good.

```
$pipeline = (new Pipeline)->pipe(function ($payload) {
    return $payload * 10;
});
```

Class based stages.
-------------------

[](#class-based-stages)

Class based stages are also possible. The StageInterface can be implemented which ensures you have the correct method signature for the `__invoke` method.

```
use League\Pipeline\Pipeline;
use League\Pipeline\StageInterface;

class TimesTwoStage implements StageInterface
{
    public function __invoke($payload)
    {
        return $payload * 2;
    }
}

class AddOneStage implements StageInterface
{
    public function __invoke($payload)
    {
        return $payload + 1;
    }
}

$pipeline = (new Pipeline)
    ->pipe(new TimesTwoStage)
    ->pipe(new AddOneStage);

// Returns 21
$pipeline->process(10);
```

Re-usable Pipelines
-------------------

[](#re-usable-pipelines)

Because the PipelineInterface is an extension of the StageInterface pipelines can be re-used as stages. This creates a highly composable model to create complex execution patterns while keeping the cognitive load low.

For example, if we'd want to compose a pipeline to process API calls, we'd create something along these lines:

```
$processApiRequest = (new Pipeline)
    ->pipe(new ExecuteHttpRequest) // 2
    ->pipe(new ParseJsonResponse); // 3

$pipeline = (new Pipeline)
    ->pipe(new ConvertToPsr7Request) // 1
    ->pipe($processApiRequest) // (2,3)
    ->pipe(new ConvertToResponseDto); // 4

$pipeline->process(new DeleteBlogPost($postId));
```

Pipeline Builders
-----------------

[](#pipeline-builders)

Because pipelines themselves are immutable, pipeline builders are introduced to facilitate distributed composition of a pipeline.

The pipeline builders collect stages and allow you to create a pipeline at any given time.

```
use League\Pipeline\PipelineBuilder;

// Prepare the builder
$pipelineBuilder = (new PipelineBuilder)
    ->add(new LogicalStage)
    ->add(new AnotherStage)
    ->add(new LastStage);

// Build the pipeline
$pipeline = $pipelineBuilder->build();
```

Exception handling
------------------

[](#exception-handling)

This package is completely transparent when dealing with exceptions. In no case will this package catch an exception or silence an error. Exceptions should be dealt with on a per-case basis. Either inside a **stage** or at the time the pipeline processes a payload.

```
$pipeline = (new Pipeline)->pipe(function () {
    throw new LogicException();
});

try {
    $pipeline->process($payload);
} catch(LogicException $e) {
    // Handle the exception.
}
```

###  Health Score

61

—

FairBetter than 99% of packages

Maintenance42

Moderate activity, may be stable

Popularity71

Solid adoption and visibility

Community46

Growing community involvement

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 73.6% 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 ~585 days

Recently: every ~837 days

Total

7

Last Release

466d ago

Major Versions

0.3.0 → 1.0.02018-06-05

PHP version history (3 changes)0.1.0PHP &gt;=5.5

1.0.0PHP &gt;=7.1

1.1.0PHP ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/534693?v=4)[Frank de Jonge](/maintainers/frankdejonge)[@frankdejonge](https://github.com/frankdejonge)

![](https://avatars.githubusercontent.com/u/38203?v=4)[Woody Gilk](/maintainers/shadowhand)[@shadowhand](https://github.com/shadowhand)

---

Top Contributors

[![frankdejonge](https://avatars.githubusercontent.com/u/534693?v=4)](https://github.com/frankdejonge "frankdejonge (78 commits)")[![shadowhand](https://avatars.githubusercontent.com/u/38203?v=4)](https://github.com/shadowhand "shadowhand (13 commits)")[![raphaelstolt](https://avatars.githubusercontent.com/u/48225?v=4)](https://github.com/raphaelstolt "raphaelstolt (2 commits)")[![nyamsprod](https://avatars.githubusercontent.com/u/51073?v=4)](https://github.com/nyamsprod "nyamsprod (2 commits)")[![jamesdb](https://avatars.githubusercontent.com/u/6299056?v=4)](https://github.com/jamesdb "jamesdb (1 commits)")[![jblotus](https://avatars.githubusercontent.com/u/382230?v=4)](https://github.com/jblotus "jblotus (1 commits)")[![leoruhland](https://avatars.githubusercontent.com/u/1785552?v=4)](https://github.com/leoruhland "leoruhland (1 commits)")[![mstnorris](https://avatars.githubusercontent.com/u/1919816?v=4)](https://github.com/mstnorris "mstnorris (1 commits)")[![pascalheidmann-check24](https://avatars.githubusercontent.com/u/167064802?v=4)](https://github.com/pascalheidmann-check24 "pascalheidmann-check24 (1 commits)")[![rishipuri](https://avatars.githubusercontent.com/u/4106278?v=4)](https://github.com/rishipuri "rishipuri (1 commits)")[![alexandrubau](https://avatars.githubusercontent.com/u/1225661?v=4)](https://github.com/alexandrubau "alexandrubau (1 commits)")[![spiliot](https://avatars.githubusercontent.com/u/1238092?v=4)](https://github.com/spiliot "spiliot (1 commits)")[![dannyvankooten](https://avatars.githubusercontent.com/u/885856?v=4)](https://github.com/dannyvankooten "dannyvankooten (1 commits)")[![duncan3dc](https://avatars.githubusercontent.com/u/546811?v=4)](https://github.com/duncan3dc "duncan3dc (1 commits)")[![hannesvdvreken](https://avatars.githubusercontent.com/u/1410358?v=4)](https://github.com/hannesvdvreken "hannesvdvreken (1 commits)")

---

Tags

patterndesign patternpipelinecompositionsequential

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[stolz/assets

An ultra-simple-to-use assets management library

296519.2k8](/packages/stolz-assets)[getsolaris/laravel-make-service

A MVCS pattern create a service command for Laravel 5+

81161.3k](/packages/getsolaris-laravel-make-service)[redeyeventures/geopattern

Generate beautiful SVG patterns.

11140.8k2](/packages/redeyeventures-geopattern)[functional-php/pattern-matching

Pattern matching for PHP with automatic destructuring.

8261.5k](/packages/functional-php-pattern-matching)[lezhnev74/pasvl

Array Validator (regular expressions for nested array, sort of)

5253.7k3](/packages/lezhnev74-pasvl)[ptrofimov/matchmaker

Ultra-fresh PHP matching functions

27167.7k](/packages/ptrofimov-matchmaker)

PHPackages © 2026

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