PHPackages                             gabbro-php/middleware - 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. [Framework](/categories/framework)
4. /
5. gabbro-php/middleware

ActiveLibrary[Framework](/categories/framework)

gabbro-php/middleware
=====================

Middleware and Routing

1.006478(7mo ago)00MITPHP

Since Sep 28Pushed 7mo agoCompare

[ Source](https://github.com/gabbro-php/middleware)[ Packagist](https://packagist.org/packages/gabbro-php/middleware)[ RSS](/packages/gabbro-php-middleware/feed)WikiDiscussions gh-main Synced 1mo ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

Gabbro - Middleware &amp; Routing
=================================

[](#gabbro---middleware--routing)

This library provides a **middleware execution engine** and a **routing component** for building HTTP services.
It is designed to be simple, explicit, and framework-agnostic — you can drop it into any project and wire up your own request/response handling.

---

Middleware Engine
-----------------

[](#middleware-engine)

At the core is the `StackEngine` contract, implemented by `OrderedStackEngine`.

- Middleware are small units of code that take a `Request`, do some work, and then either:

    - Call the next middleware in the stack, or
    - Short-circuit the pipeline and return a `Response`.
- Middleware can be registered in a specific **order**, and can be filtered by **HTTP verb flags**.
- The engine supports optional **exception catching**, so uncaught exceptions can be converted into `500 Internal Server Error` responses.

This gives you a **pipeline** model where cross-cutting concerns like logging, auth, or body parsing can be layered transparently.

---

Router
------

[](#router)

The `MiddlewareRouter` component acts as both:

- A **Router**, capable of dispatching requests to controllers based on HTTP verb and URI pattern.
- A **Middleware**, so it can slot into the stack like any other component.

### Features

[](#features)

- **Path patterns**:

    - `*` wildcard segments.
    - Placeholders: `{id}`, `{id:int}`, `{slug:alpha}`.
    - Value sets: `{status:[open|closed|pending]}`.
    - Optional segments prefixed with `?`.
- **Named routes**:
    Define routes with a name and later generate the corresponding path with dynamic values (`getNamedPath()`).
- **Binding of route parameters**:
    When a path matches, placeholders are automatically injected into the request attributes using the key format `bound-{name}`.
    Example: a route `/users/{id:int}` will yield `$request->getAttribute("bound-id")`.
- **Controller flexibility**:
    Controllers can be:

    - A callable (closure or function),
    - A class implementing the `Controller` interface, or
    - A class name string (which will be instantiated if it implements `Controller`).

---

Composition
-----------

[](#composition)

Because the router itself is a middleware, you can:

- Use `OrderedStackEngine` to build a layered stack:

    ```
    $engine = new OrderedStackEngine();
    $engine->addMiddleware(10, Verb::ANY, SomeAuthMiddleware::class);
    $engine->addMiddleware(50, Verb::GET|Verb::POST, new MiddlewareRouter());
    $response = $engine->process($request);
    ```
- Or just use the router directly if you don’t need a full middleware stack:

    ```
    $router = new MiddlewareRouter();
    $router->addRoute("/hello", Verb::GET, fn($req) => new Response("Hello World"));
    $response = $router->process($request);
    ```

---

Philosophy
----------

[](#philosophy)

This library is intentionally minimal:

- **No global state** — everything is explicit and injectable.
- **Small contracts** (`Middleware`, `StackEngine`, `Router`, `Controller`) define clear extension points.
- **Predictable behavior** — request goes in, response comes out, with optional error handling.

The idea is to give you a **solid foundation** for building your own micro-frameworks, HTTP services, or experimental backends, without forcing a specific architecture or heavy dependency tree.

---

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance62

Regular maintenance activity

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 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

233d ago

### Community

Maintainers

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

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/gabbro-php-middleware/health.svg)

```
[![Health](https://phpackages.com/badges/gabbro-php-middleware/health.svg)](https://phpackages.com/packages/gabbro-php-middleware)
```

###  Alternatives

[laravel/passport

Laravel Passport provides OAuth2 server support to Laravel.

3.4k85.0M532](/packages/laravel-passport)[nolimits4web/swiper

Most modern mobile touch slider and framework with hardware accelerated transitions

41.8k177.2k1](/packages/nolimits4web-swiper)[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k36.7M259](/packages/laravel-dusk)[laravel/prompts

Add beautiful and user-friendly forms to your command-line applications.

712181.8M596](/packages/laravel-prompts)[cakephp/chronos

A simple API extension for DateTime.

1.4k47.7M121](/packages/cakephp-chronos)[laravel/pail

Easily delve into your Laravel application's log files directly from the command line.

91545.3M590](/packages/laravel-pail)

PHPackages © 2026

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