PHPackages                             appertly/ducts - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. appertly/ducts

ActiveLibrary[HTTP &amp; Networking](/categories/http)

appertly/ducts
==============

A PSR-7 compliant middleware dispatcher for Hack/HHVM

0.1.0(10y ago)11651MITHack

Since May 26Pushed 9y ago1 watchersCompare

[ Source](https://github.com/appertly/ducts)[ Packagist](https://packagist.org/packages/appertly/ducts)[ Docs](https://github.com/appertly/ducts)[ RSS](/packages/appertly-ducts/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (5)Versions (2)Used By (1)

ducts
=====

[](#ducts)

A PSR-7 compliant middleware dispatcher for Hack/HHVM.

It's the same idea as [Connect](https://github.com/senchalabs/connect), [Relay](https://github.com/relayphp/Relay.Relay), [Stratigility](https://github.com/zendframework/zend-stratigility), [Middleman](https://github.com/mindplay-dk/middleman), etc., but in strict mode Hack.

[![Packagist](https://camo.githubusercontent.com/924a557634fceb8460297a15e1dafc2a044f8e39ada6c95c7fcddf2d4acd172f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6170706572746c792f64756374732e737667)](https://packagist.org/packages/appertly/ducts)[![Build Status](https://camo.githubusercontent.com/8c09a10b27e72987826c27a805114c5e7f0aa43b16ff3422e96fd2bd1d6d1744/68747470733a2f2f7472617669732d63692e6f72672f6170706572746c792f64756374732e737667)](https://travis-ci.org/appertly/ducts)

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

[](#installation)

You can install this library using Composer:

```
$ composer require appertly/ducts
```

- The master branch (version 0.x) of this project requires HHVM 3.12 and has no dependencies.

Compliance
----------

[](#compliance)

Releases of this library will conform to [Semantic Versioning](http://semver.org).

Our code is intended to comply with [PSR-1](http://www.php-fig.org/psr/psr-1/), [PSR-2](http://www.php-fig.org/psr/psr-2/), and [PSR-4](http://www.php-fig.org/psr/psr-4/). If you find any issues related to standards compliance, please send a pull request!

Layers and Dispatching
----------------------

[](#layers-and-dispatching)

The idea here is that you supply a list of functions which:

1. Accept a request, a response, and a next function
2. Possibly modify the request and response
3. Possibly invoke the next function, which returns a response
4. Possibly modify the returned response
5. Return the response

```
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;

function foobar(Request $req, Response $res, (function (Request,Response): Response) $next): Response
{
    // 2. possibly modify the request and response
    // 3. invoke next
    $res = $next($req, $res);
    // 4. possibly modify response
    // 5.
    return $res;
}
```

Layers end up interacting like this:

- → First layer
    - → Second layer
        - → Third layer
        - ← Third layer
    - ← Second layer
- ← First layer

### Dispatch a Request

[](#dispatch-a-request)

```
use Ducts\Runner;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;

/**
 * @var \Psr\Http\Message\ServerRequestInterface $request The PSR-7 HTTP request
 * @var \Psr\Http\Message\ResponseInterface $response The PSR-7 HTTP response
 */

// any Traversable will do. Use an array, Vector, etc.
$runner = new Runner([
    // you can use closures
    function(Request $req, Response $res, (function (Request,Response): Response) $next): Response {
        $req = $req->withAttribute('foo', 'bar');
        return $next($req, $res);
    },
    // or lambdas
    ($req, $res, $next) ==> $next($req, $res)->withHeader('X-Ducts', 'Yes')
    // or objects with an __invoke method
    new MyInvokableThing(),
    // or Hack-style callables
    fun('myLayer'),
    class_meth('MyLayer', 'staticMethod'),
    inst_meth($myObject, 'layer')
]);

$response = $runner->run($request, $response);

// Runner::run can be called multiple times if needed
$anotherResponse = $runner->run($request, $response);
```

You can also make use of the `ResolvingRunner` if you'd like to look up the layer callable.

```
// a function to look up names
$resolver = function(mixed $name): (function (Request,Response,(function(Request,Response): Response)): Response) {
    // look up your callable thing in a dependency injection container
    $container = MyClass::getSomeContainer();
    return $container->get($name);
};

// Items in this traversable can be a combination of functions or items to resolve
$runner = new ResolvingRunner([
    ($req, $res, $next) ==> $next($req, $res)->withHeader('X-Ducts', 'Yes'),
    'MyClassName',
    'AnotherClass'
], $resolver);
```

### A Runner as a Layer

[](#a-runner-as-a-layer)

You can use a `Runner` as a layer by calling `$runner->layer()`! For example, you declare `Runner` `$bar` to be the second layer of three in `Runner` `$foo`. If `$bar` has three layers, it will participate in `$foo` like this:

- → `$foo` layer 1
    - → `$bar` layer 1
        - → `$bar` layer 2
            - → `$bar` layer 3
                - → `$foo` layer 3
                - ← `$foo` layer 3
            - ← `$bar` layer 3
        - ← `$bar` layer 2
    - ← `$bar` layer 1
- ← `$foo` layer 1

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity53

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

Unknown

Total

1

Last Release

3687d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/659262eac941ffe4795493834425fc9a2369c2c9df3cc565ed4194f1d37be934?d=identicon)[doublecompile](/maintainers/doublecompile)

---

Top Contributors

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

---

Tags

psr-7middlewarehhvmhack

### Embed Badge

![Health badge](/badges/appertly-ducts/health.svg)

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

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

7.9k1.1B3.8k](/packages/guzzlehttp-psr7)[symfony/psr-http-message-bridge

PSR HTTP message bridge

1.3k312.3M931](/packages/symfony-psr-http-message-bridge)[mezzio/mezzio

PSR-15 Middleware Microframework

3913.8M120](/packages/mezzio-mezzio)[psr/http-server-middleware

Common interface for HTTP server-side middleware

18499.3M1.8k](/packages/psr-http-server-middleware)[laminas/laminas-stratigility

PSR-7 middleware foundation for building and dispatching middleware pipelines

577.0M95](/packages/laminas-laminas-stratigility)[mezzio/mezzio-authentication-oauth2

OAuth2 (server) authentication middleware for Mezzio and PSR-7 applications.

28545.4k3](/packages/mezzio-mezzio-authentication-oauth2)

PHPackages © 2026

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