PHPackages                             nazg/heredity - 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. nazg/heredity

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

nazg/heredity
=============

Middleware Dispatcher For Hack

1.12.2(5y ago)06.3k1MITHack

Since Jan 19Pushed 5y ago1 watchersCompare

[ Source](https://github.com/nazg-hack/heredity)[ Packagist](https://packagist.org/packages/nazg/heredity)[ Docs](https://github.com/nazg-hack/heredity)[ RSS](/packages/nazg-heredity/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (10)Dependencies (11)Versions (27)Used By (1)

heredity
========

[](#heredity)

Middleware Dispatcher For Hack.

[![Build Status](https://camo.githubusercontent.com/51ac9251bda049b39f482d8fe6155f3a847934bb3462ea3606762d6951a218c3/68747470733a2f2f7472617669732d63692e6f72672f6e617a672d6861636b2f68657265646974792e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/nazg-hack/heredity)

PSR-7 HTTP message library Not Supported.
Supported Only Hack library.
*Required HHVM &gt;= 4.20.0*

- [ytake/hungrr](https://github.com/ytake/hungrr)
- [usox/hackttp](https://github.com/usox/hackttp)

install
-------

[](#install)

```
$ composer require nazg/heredity
```

Usage
-----

[](#usage)

### Basic

[](#basic)

#### 1. Example Simple Request Handler

[](#1-example-simple-request-handler)

```
use type Nazg\Http\Server\RequestHandlerInterface;
use type Facebook\Experimental\Http\Message\ServerRequestInterface;
use type Facebook\Experimental\Http\Message\ResponseInterface;
use type Ytake\Hungrr\Response;
use type Ytake\Hungrr\StatusCode;
use type NazgHeredityTest\Middleware\MockMiddleware;
use namespace HH\Lib\Experimental\IO;
use function json_encode;

final class SimpleRequestHandler implements RequestHandlerInterface {

  public function handle(
    IO\WriteHandle $handle,
    ServerRequestInterface $request
  ): ResponseInterface {
    $header = $request->getHeader(MockMiddleware::MOCK_HEADER);
    if (count($header)) {
      $handle->rawWriteBlocking(json_encode($header));
      return new Response($handle, StatusCode::OK);
    }
    $handle->rawWriteBlocking(json_encode([]));
    return new Response($handle, StatusCode::OK);
  }
}
```

#### 2. Creating Middleware

[](#2-creating-middleware)

```
use type Facebook\Experimental\Http\Message\ResponseInterface;
use type Facebook\Experimental\Http\Message\ServerRequestInterface;
use type Nazg\Http\Server\MiddlewareInterface;
use type Nazg\Http\Server\RequestHandlerInterface;
use type HH\Lib\Experimental\IO\WriteHandle;

class SimpleMiddleware implements MiddlewareInterface {

  public function process(
    WriteHandle $writeHandle,
    ServerRequestInterface $request,
    RequestHandlerInterface $handler,
  ): ResponseInterface {
    // ... do something and return response
    return $handler->handle($writeHandle, $request);
  }
}
```

#### 3. Middleware

[](#3-middleware)

```
use type Nazg\Heredity\Heredity;
use type Nazg\Heredity\MiddlewareStack;
use type Ytake\Hungrr\ServerRequestFactory;
use namespace HH\Lib\Experimental\IO;

list($read, $write) = IO\pipe_non_disposable();
$heredity = new Heredity(
    new MiddlewareStack([
      SimpleMiddleware::class
    ]),
    new SimpleRequestHandler()
  );
$response = $heredity->handle($write, ServerRequestFactory::fromGlobals());
```

### With Dependency Injection Container

[](#with-dependency-injection-container)

example. [nazg-hack/glue](https://github.com/nazg-hack/glue)

```
use namespace HH\Lib\Str;
use type Nazg\Http\Server\AsyncMiddlewareInterface;
use type Nazg\Heredity\Exception\MiddlewareResolvingException;
use type Nazg\Heredity\Resolvable;
use type Nazg\Glue\Container;

class GlueResolver implements Resolvable {

  public function __construct(
    protected Container $container
  ) {}

  public function resolve(
    classname $middleware
  ): AsyncMiddlewareInterface {
    if ($this->container->has($middleware)) {
      return $this->container->get($middleware);
    }
    throw new MiddlewareResolvingException(
      Str\format('Identifier "%s" is not binding.', $middleware),
    );
  }
}
```

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity73

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

Recently: every ~25 days

Total

24

Last Release

2134d ago

Major Versions

0.4.0 → 1.0.02018-11-27

### Community

Maintainers

![](https://www.gravatar.com/avatar/47817f3dd2890864096bd77ee772ec46061432f128988ca23939b0ca486d7bc3?d=identicon)[ytake](/maintainers/ytake)

---

Top Contributors

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

---

Tags

hackmiddlewarepsr-15psr-7httpresponserequestmiddlewarehhvmhack

### Embed Badge

![Health badge](/badges/nazg-heredity/health.svg)

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

###  Alternatives

[psr/http-server-middleware

Common interface for HTTP server-side middleware

18091.2M1.5k](/packages/psr-http-server-middleware)[elementaryframework/water-pipe

URL routing framework and requests/responses handler for PHP

254.6k4](/packages/elementaryframework-water-pipe)

PHPackages © 2026

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