PHPackages                             babicaja/chainer - 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. babicaja/chainer

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

babicaja/chainer
================

Chain your actions and make a complex workflow more readable

v1.1.1(4y ago)425[1 PRs](https://github.com/babicaja/chainer/pulls)MITPHPPHP ^7.4|^8.0

Since Oct 19Pushed 2y ago1 watchersCompare

[ Source](https://github.com/babicaja/chainer)[ Packagist](https://packagist.org/packages/babicaja/chainer)[ RSS](/packages/babicaja-chainer/feed)WikiDiscussions master Synced today

READMEChangelog (3)Dependencies (4)Versions (10)Used By (0)

Chainer
=======

[](#chainer)

> Chain your actions and make a complex workflow more readable

[![Latest Version on Packagist](https://camo.githubusercontent.com/fec0ed606dfd0bb1b1e9019dd81656e6e28b31e15146496a94f5003097fbc0c7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6261626963616a612f636861696e6572)](https://packagist.org/packages/babicaja/chainer)[![Total Downloads](https://camo.githubusercontent.com/10029da50b31fdad6388797f5c6524a5726e5e4910c8df8cac71fcb510cb82c6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6261626963616a612f636861696e6572)](https://packagist.org/packages/babicaja/chainer)[![tests](https://github.com/babicaja/chainer/workflows/tests/badge.svg)](https://github.com/babicaja/chainer/workflows/tests/badge.svg)[![Coverage](https://camo.githubusercontent.com/604e06041b0c3f2774fafcd3338b1ae25f0d9563f76378f21fb1fd041857be40/68747470733a2f2f636f6465636f762e696f2f67682f6261626963616a612f636861696e65722f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/babicaja/chainer)[![Licence](https://camo.githubusercontent.com/0e357539b3ad3381911b195203539d8da595e2908c74f7afd95047310c348a20/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6261626963616a612f636861696e6572)](https://github.com/babicaja/chainer)

- [Installation](#installation)
- [Usage](#usage)
- [Contributing](#contributing)

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

[](#installation)

Install `Chainer` using composer with the following command

```
composer require babicaja/chainer
```

Usage
-----

[](#usage)

Chain actions and pass any type of payload through a simple interface

```
Chain::do(TaskOne::class)
->then(TaskTwo::class)
->then(TaskThree::class)
->run('payload');
```

The actions passed to the `Chainer\Chain->then()` method can be any of the following

- [Link Instance](#link-instance)
- [Chain Instance](#chain-instance)
- [Invokable Class](#invokable-class)
- [Callback / Callable](#callback--callable)

### Link Instance

[](#link-instance)

ℹ️ Link can be an instance or fqn `Chain::do(new FirstAction())` or `Chain::do(FirstAction::class)````
namespace Examples;

use Chainer\Chain;
use Chainer\Link;

class FirstAction extends Link
{
    public function handle($payload = null)
    {
        $payload[] = __METHOD__;
        return $payload;
    }
}

class SecondAction extends Link
{
    public function handle($payload = null)
    {
        $payload[] = __METHOD__;
        return $payload;
    }
}

$result = Chain::do(FirstAction::class)
    ->then(SecondAction::class)
    ->run();

echo json_encode($result);
```

Result

```
[
    "Examples\\FirstAction::handle",
    "Examples\\SecondAction::handle"
]
```

### Chain Instance

[](#chain-instance)

```
namespace Examples;

use Chainer\Chain;
use Chainer\Link;

class FirstAction extends Link
{
    public function handle($payload = null)
    {
        $payload[] = __METHOD__;
        return $payload;
    }
}

class SecondAction extends Link
{
    public function handle($payload = null)
    {
        $payload[] = __METHOD__;
        return $payload;
    }
}

$chain = Chain::do(FirstAction::class)
    ->then(SecondAction::class);

$result = Chain::do($chain)
    ->then(FirstAction::class)
    ->run([]);

echo json_encode($result);
```

Result

```
[
    "Examples\\FirstAction::handle",
    "Examples\\SecondAction::handle",
    "Examples\\FirstAction::handle"
]
```

### Invokable Class

[](#invokable-class)

ℹ️ Invokable can be an instance or fqn `Chain::do(new FirstAction())` or `Chain::do(FirstAction::class)````
namespace Examples;

use Chainer\Chain;

class FirstAction
{
    public function __invoke($payload = null)
    {
        $payload[] = __METHOD__;
        return $payload;
    }
}

class SecondAction
{
    public function __invoke($payload = null)
    {
        $payload[] = __METHOD__;
        return $payload;
    }
}

$result = Chain::do(FirstAction::class)
    ->then(SecondAction::class)
    ->run();

echo json_encode($result);
```

Result

```
[
    "Examples\\FirstAction::__invoke",
    "Examples\\SecondAction::__invoke"
]
```

### Callback / Callable

[](#callback--callable)

```
namespace Examples;

use Chainer\Chain;

function helper($payload)
{
    $payload[] = __METHOD__;
    return $payload;
}

class Util
{
    public function method($payload)
    {
        $payload[] = __METHOD__;
        return $payload;
    }

    public static function staticMethod($payload)
    {
        $payload[] = __METHOD__;
        return $payload;
    }
}

class App
{
    public function run()
    {
        return Chain::do(fn($payload) => $this->method($payload))
            ->then(fn($payload) => self::staticMethod($payload))
            ->then([new Util(), 'method'])
            ->then([Util::class, 'staticMethod'])
            ->then('Examples\helper')
            ->then(function ($payload) {
                $payload[] = __METHOD__;
                return $payload;
            })
            ->run([]);
    }

    private function method($payload)
    {
        $payload[] = __METHOD__;
        return $payload;
    }

    private static function staticMethod($payload)
    {
        $payload[] = __METHOD__;
        return $payload;
    }
}

$app = new App();
echo json_encode($app->run());
```

Result

```
[
    "Examples\\App::method",
    "Examples\\App::staticMethod",
    "Examples\\Util::method",
    "Examples\\Util::staticMethod",
    "Examples\\helper",
    "Examples\\{closure}"
]
```

Contributing
------------

[](#contributing)

Contributors:

- [babicaja](https://github.com/babicaja)

You are more than welcome to contribute to this project. The main goal is to keep it simple because there are more than enough libraries with advance features. To take your work into consideration please create a Pull Request along the following guidelines:

```
## What's the purpose of this PR?
(Insert the description of the purpose of this change here)
## Impact Analysis
(What will this possibly affect?)
## Where should the tester start?
(Hints tips or tricks regarding how to test this, things to watch out for, etc)
## What are the relevant tickets?
(Is this related to a ticket/bug at the moment?)

```

Don't forget to write unit tests! All contributors will be listed.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 98.4% 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 ~64 days

Recently: every ~96 days

Total

7

Last Release

1644d ago

Major Versions

v0.4.0 → v1.0.02020-10-23

PHP version history (2 changes)v0.1.0PHP ^7.4

v1.1.1PHP ^7.4|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/47e83a35ef35490500512f18307661e3035bedbd2250a15320ba33a15b71595c?d=identicon)[babicaja](/maintainers/babicaja)

---

Top Contributors

[![babicaja](https://avatars.githubusercontent.com/u/6343738?v=4)](https://github.com/babicaja "babicaja (62 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

callbackchain-of-responsibilitychainercomposerflowphp7pipelinkflowChainchain of responsibility

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/babicaja-chainer/health.svg)

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

###  Alternatives

[jbroadway/urlify

A fast PHP slug generator and transliteration library that converts non-ascii characters for use in URLs.

6737.4M62](/packages/jbroadway-urlify)[misd/linkify

Converts URLs and email addresses in text into HTML links

1122.9M10](/packages/misd-linkify)[phpmentors/workflower

A BPMN 2.0 workflow engine for PHP

70652.9k4](/packages/phpmentors-workflower)[iamcal/lib_autolink

Adds anchors to urls in a text

631.3M3](/packages/iamcal-lib-autolink)[shivella/laravel-bitly

Laravel package for generating bitly url

75789.0k1](/packages/shivella-laravel-bitly)[voku/urlify

PHP port of URLify.js from the Django project. Transliterates non-ascii characters for use in URLs.

254.1M7](/packages/voku-urlify)

PHPackages © 2026

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