PHPackages                             optimus/onion - 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. optimus/onion

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

optimus/onion
=============

1.0.0(9y ago)72118.8k↓48.7%18[1 PRs](https://github.com/esbenp/onion/pulls)14MITPHP

Since Jul 1Pushed 6y ago4 watchersCompare

[ Source](https://github.com/esbenp/onion)[ Packagist](https://packagist.org/packages/optimus/onion)[ RSS](/packages/optimus-onion/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (2)Dependencies (4)Versions (3)Used By (14)

Onion
=====

[](#onion)

[![Build Status](https://camo.githubusercontent.com/15369748bf30317b0605e5857f417977232669bfa07e601d0ba3a195f5305385/68747470733a2f2f7472617669732d63692e6f72672f657362656e702f6f6e696f6e2e737667)](https://travis-ci.org/esbenp/onion) [![Coverage Status](https://camo.githubusercontent.com/18c2c990622c0e78dfc8f058e99d05f25a5c1c9f19bd8ebb2aad4751cb4988d3/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f657362656e702f6f6e696f6e2f62616467652e7376673f6272616e63683d6d617374657226736572766963653d676974687562)](https://coveralls.io/github/esbenp/onion?branch=master)

A standalone middleware library without dependencies inspired by middleware in Laravel (Illuminate/Pipeline).

I have written a small blog post about the library and how to use it: [Implementing before/after middleware in PHP](http://esbenp.github.io/2015/07/31/implementing-before-after-middleware/)

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

[](#installation)

```
composer require optimus/onion ~1.0
```

Usage
-----

[](#usage)

```
class BeforeLayer implements LayerInterface {

    public function peel($object, Closure $next)
    {
        $object->runs[] = 'before';

        return $next($object);
    }

}

class AfterLayer implements LayerInterface {

    public function peel($object, Closure $next)
    {
        $response = $next($object);

        $object->runs[] = 'after';

        return $response;
    }

}

$object = new StdClass;
$object->runs = [];

$onion = new Onion;
$end = $onion->layer([
                new AfterLayer(),
                new BeforeLayer(),
                new AfterLayer(),
                new BeforeLayer()
            ])
            ->peel($object, function($object){
                $object->runs[] = 'core';
                return $object;
            });

var_dump($end);
```

Will output

```
..object(stdClass)#161 (1) {
  ["runs"]=>
  array(5) {
    [0]=>
    string(6) "before"
    [1]=>
    string(6) "before"
    [2]=>
    string(4) "core"
    [3]=>
    string(5) "after"
    [4]=>
    string(5) "after"
  }
}

```

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity46

Moderate usage in the ecosystem

Community25

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 90.9% 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 ~559 days

Total

2

Last Release

3462d ago

Major Versions

0.1.0 → 1.0.02017-01-10

### Community

Maintainers

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

---

Top Contributors

[![esbenp](https://avatars.githubusercontent.com/u/934819?v=4)](https://github.com/esbenp "esbenp (10 commits)")[![MBoretto](https://avatars.githubusercontent.com/u/6514506?v=4)](https://github.com/MBoretto "MBoretto (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/optimus-onion/health.svg)

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

###  Alternatives

[talan-hdf/semantic-suggestion

TYPO3 extension for suggesting semantically related pages using advanced NLP and TF-IDF analysis

102.6k](/packages/talan-hdf-semantic-suggestion)

PHPackages © 2026

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