PHPackages                             stack/builder - 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. stack/builder

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

stack/builder
=============

Builder for stack middleware based on HttpKernelInterface.

v1.0.6(6y ago)29443.2M—2.7%28[1 PRs](https://github.com/stackphp/builder/pulls)20MITPHPPHP &gt;=7.2.0

Since Aug 2Pushed 4y ago11 watchersCompare

[ Source](https://github.com/stackphp/builder)[ Packagist](https://packagist.org/packages/stack/builder)[ RSS](/packages/stack-builder/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (8)Used By (20)

Stack/Builder
=============

[](#stackbuilder)

Builder for stack middlewares based on HttpKernelInterface.

Stack/Builder is a small library that helps you construct a nested HttpKernelInterface decorator tree. It models it as a stack of middlewares.

Example
-------

[](#example)

If you want to decorate a [silex](https://github.com/fabpot/Silex) app with session and cache middlewares, you'll have to do something like this:

```
use Symfony\Component\HttpKernel\HttpCache\Store;

$app = new Silex\Application();

$app->get('/', function () {
    return 'Hello World!';
});

$app = new Stack\Session(
    new Symfony\Component\HttpKernel\HttpCache\HttpCache(
        $app,
        new Store(__DIR__.'/cache')
    )
);
```

This can get quite annoying indeed. Stack/Builder simplifies that:

```
$stack = (new Stack\Builder())
    ->push('Stack\Session')
    ->push('Symfony\Component\HttpKernel\HttpCache\HttpCache', new Store(__DIR__.'/cache'));

$app = $stack->resolve($app);
```

As you can see, by arranging the layers as a stack, they become a lot easier to work with.

In the front controller, you need to serve the request:

```
use Symfony\Component\HttpFoundation\Request;

$request = Request::createFromGlobals();
$response = $app->handle($request)->send();
$app->terminate($request, $response);
```

Stack/Builder also supports pushing a `callable` on to the stack, for situations where instantiating middlewares might be more complicated. The `callable` should accept a `HttpKernelInterface` as the first argument and should also return a `HttpKernelInterface`. The example above could be rewritten as:

```
$stack = (new Stack\Builder())
    ->push('Stack\Session')
    ->push(function ($app) {
        $cache = new HttpCache($app, new Store(__DIR__.'/cache'));
        return $cache;
    })
;
```

Inspiration
-----------

[](#inspiration)

- [Rack::Builder](http://rack.rubyforge.org/doc/Rack/Builder.html)
- [HttpKernel middlewares](https://igor.io/2013/02/02/http-kernel-middlewares.html)

###  Health Score

50

—

FairBetter than 96% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity67

Solid adoption and visibility

Community39

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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

Recently: every ~548 days

Total

7

Last Release

2300d ago

PHP version history (3 changes)v1.0.0PHP &gt;=5.4.0

v1.0.1PHP &gt;=5.3.0

v1.0.6PHP &gt;=7.2.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/3afcc18d00fff840775bbf9570b3e9cd3997ca4820b9bfb14caf6da3ae580370?d=identicon)[igorw](/maintainers/igorw)

---

Top Contributors

[![igorw](https://avatars.githubusercontent.com/u/88061?v=4)](https://github.com/igorw "igorw (27 commits)")[![simensen](https://avatars.githubusercontent.com/u/191200?v=4)](https://github.com/simensen "simensen (8 commits)")[![bajb](https://avatars.githubusercontent.com/u/2241334?v=4)](https://github.com/bajb "bajb (6 commits)")[![fabpot](https://avatars.githubusercontent.com/u/47313?v=4)](https://github.com/fabpot "fabpot (4 commits)")[![davedevelopment](https://avatars.githubusercontent.com/u/61351?v=4)](https://github.com/davedevelopment "davedevelopment (4 commits)")[![tarekdj](https://avatars.githubusercontent.com/u/540268?v=4)](https://github.com/tarekdj "tarekdj (3 commits)")[![CHH](https://avatars.githubusercontent.com/u/16783?v=4)](https://github.com/CHH "CHH (2 commits)")[![GrahamCampbell](https://avatars.githubusercontent.com/u/2829600?v=4)](https://github.com/GrahamCampbell "GrahamCampbell (1 commits)")[![h4cc](https://avatars.githubusercontent.com/u/2981491?v=4)](https://github.com/h4cc "h4cc (1 commits)")[![dawehner](https://avatars.githubusercontent.com/u/29678?v=4)](https://github.com/dawehner "dawehner (1 commits)")[![digitalkaoz](https://avatars.githubusercontent.com/u/293591?v=4)](https://github.com/digitalkaoz "digitalkaoz (1 commits)")[![LionsHead](https://avatars.githubusercontent.com/u/2943862?v=4)](https://github.com/LionsHead "LionsHead (1 commits)")[![Nyholm](https://avatars.githubusercontent.com/u/1275206?v=4)](https://github.com/Nyholm "Nyholm (1 commits)")[![danielmadu](https://avatars.githubusercontent.com/u/3596439?v=4)](https://github.com/danielmadu "danielmadu (1 commits)")[![jjsaunier](https://avatars.githubusercontent.com/u/1763341?v=4)](https://github.com/jjsaunier "jjsaunier (1 commits)")

---

Tags

stack

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/stack-builder/health.svg)

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

###  Alternatives

[nelmio/api-doc-bundle

Generates documentation for your REST API from attributes

2.3k63.6M233](/packages/nelmio-api-doc-bundle)[api-platform/core

Build a fully-featured hypermedia or GraphQL API in minutes!

2.6k48.1M236](/packages/api-platform-core)[asm89/stack-cors

Cross-origin resource sharing library and stack middleware

1.3k180.6M24](/packages/asm89-stack-cors)[friendsofsymfony/http-cache-bundle

Set path based HTTP cache headers and send invalidation requests to your HTTP cache

43813.2M47](/packages/friendsofsymfony-http-cache-bundle)[illuminate/http

The Illuminate Http package.

11936.0M5.1k](/packages/illuminate-http)[api-platform/state

API Platform state interfaces

223.4M57](/packages/api-platform-state)

PHPackages © 2026

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