PHPackages                             bartosz-maciaszek/chain - 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. bartosz-maciaszek/chain

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

bartosz-maciaszek/chain
=======================

Actions chaining made easy for PHP7

06.7k1PHP

Since Sep 17Pushed 9y ago1 watchersCompare

[ Source](https://github.com/bartosz-maciaszek/chain)[ Packagist](https://packagist.org/packages/bartosz-maciaszek/chain)[ RSS](/packages/bartosz-maciaszek-chain/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependenciesVersions (1)Used By (0)

[![Build Status](https://camo.githubusercontent.com/8e5a8c543933e338acf90aa7de4bce871c28dc6dc5cf1d981d20575adb7b2690/68747470733a2f2f7472617669732d63692e6f72672f626172746f737a2d6d61636961737a656b2f636861696e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/bartosz-maciaszek/chain)[![Minimum PHP Version](https://camo.githubusercontent.com/5c3072425e67297c8ef63d17acd2c86a0d2ef324f19249f2280bd7de902f63a2/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230372e302d3838393242462e737667)](https://php.net/)[![Dependency Status](https://camo.githubusercontent.com/dd7fe20382b3867dbcf9ea3ed6f8e65631d9e4d91e3544f52baaded377c0abd0/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3537646433383663303337633230303034353866366235612f62616467652e7376673f7374796c653d666c6174)](https://www.versioneye.com/user/projects/57dd386c037c2000458f6b5a)

About
=====

[](#about)

This is a simple library that makes it easier to chain actions/processors. Useful for any kind of data processing with reusable pieces of code in a specific order.

The library is inspired with Chain of Responsibility design pattern and middleware-like approach where one middleware executes its logic and, conditionally, runs next middleware.

How do I install it?
--------------------

[](#how-do-i-install-it)

```
composer require bartosz-maciaszek/chain

```

How do I use it?
----------------

[](#how-do-i-use-it)

In three simple steps:

1. Create a context class that implements `BM\Chain\ChainContextInterface`.
2. Create an instance of `BM\Chain\ProcessorsQueue` and register processor with it.
3. Execute the chain by invoking `execute()` method and passing the context object.

What is the context class?
--------------------------

[](#what-is-the-context-class)

This is a class that stores some information and is being passed to each of the registered processor. Context can contain some initial input data of any type. Processors are meant to use that data during execution. Obviously, they can always store anything in the context. You're in charge here.

What are the processors?
------------------------

[](#what-are-the-processors)

Processors are `callable`'s that contain some logic to be executed. They can be closures or classes implementing `__invoke` method. The processors always take two arguments: context and next processor in the queue. They are responsible for execution of next one, otherwise the chain breaks.

What is the processor queue?
----------------------------

[](#what-is-the-processor-queue)

Processor queue is an object that aggregates processors in the given order. It exposes methods that allow managing processors.

What is the chain?
------------------

[](#what-is-the-chain)

Chain is a class that is responsible for execution of the processor queue and passing the context object to them.

Any examples?
-------------

[](#any-examples)

Have a look [here](examples).

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1911210?v=4)[Bartosz Maciaszek](/maintainers/bartosz-maciaszek)[@bartosz-maciaszek](https://github.com/bartosz-maciaszek)

---

Top Contributors

[![bartosz-maciaszek](https://avatars.githubusercontent.com/u/1911210?v=4)](https://github.com/bartosz-maciaszek "bartosz-maciaszek (14 commits)")

### Embed Badge

![Health badge](/badges/bartosz-maciaszek-chain/health.svg)

```
[![Health](https://phpackages.com/badges/bartosz-maciaszek-chain/health.svg)](https://phpackages.com/packages/bartosz-maciaszek-chain)
```

PHPackages © 2026

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