PHPackages                             alcidesrc/sequence - 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. alcidesrc/sequence

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

alcidesrc/sequence
==================

A PHP implementation of Chain of Responsability pattern

1.0.1(5mo ago)13MITPHPPHP ^8.4CI passing

Since Apr 24Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/AlcidesRC/sequence)[ Packagist](https://packagist.org/packages/alcidesrc/sequence)[ RSS](/packages/alcidesrc-sequence/feed)WikiDiscussions main Synced yesterday

READMEChangelog (2)Dependencies (7)Versions (3)Used By (0)

[![Continuous Integration](https://github.com/fonil/sequence/actions/workflows/ci.yml/badge.svg)](https://github.com/fonil/sequence/actions/workflows/ci.yml)

Sequence
========

[](#sequence)

> Sequence your tasks and make complex workflows more readable

\[TOC\]

Summary
-------

[](#summary)

This repository contains a [Chain of Responsability](https://refactoring.guru/design-patterns/chain-of-responsibility) design pattern implementation built with PHP.

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

[](#requirements)

This library requires PHP^8.3

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

[](#installation)

Install `Sequence` using Composer:

```
composer require fonil/sequence
```

Usage
-----

[](#usage)

Create a `Sequence` instance and attach any type of payload through a simple interface:

```
$result = Sequence::run(FirstTask::class)
	->then(SecondTask::class)
	...
	->then(LastTask::class)
	->startWith('payload');
```

### Tasks

[](#tasks)

`Sequence` requires at least a task to be run. You can attach any of the following entities as a task:

- [Invokable Class](#invokable-class)
- [Explicit Task](#explicit-task)
- [Custom Class](#custom-class)
- [Static Method](#static-method)
- [Closure / Callback / Callable](#closure--callback--callable)

#### Invokable Class

[](#invokable-class)

```
class InvokableIncrementCounter
{
    public function __invoke(array $payload): array
    {
        $payload['counter']++;
        return $payload;
    }
}

$result = Sequence::run(InvokableIncrementCounter::class)
    ->startWith(['counter' => 0]);

echo json_encode($result);
// {"counter":1}
```

#### Explicit Task

[](#explicit-task)

```
class IncrementTask implements TaskInterface
{
    //...

    public function handle(mixed $payload = null): mixed
    {
        $payload['counter']++;
        return $payload;
    }
}

$result = Sequence::run(IncrementTask::class)
    ->startWith(['counter' => 0]);

echo json_encode($result);
// {"counter":1}
```

#### Custom Class

[](#custom-class)

```
class IncrementCounter
{
    public function add(array $payload): array
    {
        $payload['counter']++;
        return $payload;
    }
}

$result = Sequence::run([IncrementCounter::class, 'add'])
    ->startWith(['counter' => 0]);

// OR

$result = Sequence::run([new IncrementCounter(), 'add'])
    ->startWith(['counter' => 0]);

echo json_encode($result);
// {"counter":1}
```

#### Static Method

[](#static-method)

```
class IncrementCounter
{
    public static function add(array $payload): array
    {
        $payload['counter']++;
        return $payload;
    }
}

$result = Sequence::run([IncrementCounter::class, 'add'])
    ->startWith(['counter' => 0]);

echo json_encode($result);
// {"counter":1}
```

#### Closure / Callback / Callable

[](#closure--callback--callable)

```
$closure = function (array $payload): array {
    $payload['counter']++;
    return $payload;
};

$result = Sequence::run($closure)
    ->startWith(['counter' => 0]);

echo json_encode($result);
// {"counter":1}
```

#### Sequence Instance

[](#sequence-instance)

```
$closure = function (array $payload): array {
    $payload['counter']++;
    return $payload;
};

$sequence = Sequence::run($closure)->then($closure);

$result = Sequence::run($sequence)
    ->startWith(['counter' => 0]);

echo json_encode($result);
// {"counter":2}
```

### Examples

[](#examples)

```
$result = Sequence::run($closure)			// 1st execution => $counter is 1
	->then(InvokableIncrementCounter::class)	// 2nd execution => $counter is 2
	->then([IncrementCounter::class, 'increment'])	// 3rd execution => $counter is 3
	->then(IncrementTask::class)			// 4th execution => $counter is 4
	->startWith(['counter' => 0]);

echo json_encode($result);
// {"counter":4}
```

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review our security policy on how to report security vulnerabilities:

**PLEASE DON'T DISCLOSE SECURITY-RELATED ISSUES PUBLICLY**

### Supported Versions

[](#supported-versions)

Only the latest major version receives security fixes.

### Reporting a Vulnerability

[](#reporting-a-vulnerability)

If you discover a security vulnerability within this project, please [open an issue here](https://github.com/fonil/sequence/issues). All security vulnerabilities will be promptly addressed.

License
-------

[](#license)

The MIT License (MIT). Please see [LICENSE](./LICENSE) file for more information.

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance72

Regular maintenance activity

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

 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 ~643 days

Total

2

Last Release

157d ago

PHP version history (2 changes)1.0.0PHP ^8.3

1.0.1PHP ^8.4

### Community

Maintainers

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

---

Top Contributors

[![AlcidesRC](https://avatars.githubusercontent.com/u/1401102?v=4)](https://github.com/AlcidesRC "AlcidesRC (9 commits)")

---

Tags

phptaskflowsequencechain of responsibility

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/alcidesrc-sequence/health.svg)

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

###  Alternatives

[phing/phing

PHing Is Not GNU make; it's a PHP project build system or build tool based on Apache Ant.

1.2k22.5M911](/packages/phing-phing)[reisraff/phulp

The task manager for PHP

29412.2k10](/packages/reisraff-phulp)[pmill/php-scheduler

Simple PHP task scheduler

1834.5k](/packages/pmill-php-scheduler)[luka-dev/headless-task-server-php

Helper for sending requests to luka-dev/headless-task-server

1010.0k](/packages/luka-dev-headless-task-server-php)

PHPackages © 2026

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