PHPackages                             fyre/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. [Queues &amp; Workers](/categories/queues)
4. /
5. fyre/middleware

ActiveLibrary[Queues &amp; Workers](/categories/queues)

fyre/middleware
===============

A middleware library.

v7.0.1(7mo ago)0343↓81.8%9MITPHP

Since Jan 3Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/elusivecodes/FyreMiddleware)[ Packagist](https://packagist.org/packages/fyre/middleware)[ RSS](/packages/fyre-middleware/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (10)Dependencies (8)Versions (34)Used By (9)

FyreMiddleware
==============

[](#fyremiddleware)

**FyreMiddleware** is a free, open-source middleware library for *PHP*.

Table Of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Basic Usage](#basic-usage)
- [Methods](#methods)
- [Middleware Queues](#middleware-queues)
    - [Middleware](#middleware)
- [Request Handlers](#request-handlers)

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

[](#installation)

**Using Composer**

```
composer require fyre/middleware

```

In PHP:

```
use Fyre\Middleware\MiddlewareRegistry;
```

Basic Usage
-----------

[](#basic-usage)

- `$container` is a [*Container*](https://github.com/elusivecodes/FyreContainer).

```
$middlewareRegistry = new MiddlewareRegistry($container);
```

It is recommended to bind the *MiddlewareRegistry* to the [*Container*](https://github.com/elusivecodes/FyreContainer) as a singleton.

```
$container->singleton(MiddlewareRegistry::class);
```

Any dependencies will be injected automatically when loading from the [*Container*](https://github.com/elusivecodes/FyreContainer).

```
$middlewareRegistry = $container->use(MiddlewareRegistry::class);
```

Methods
-------

[](#methods)

**Clear**

Clear all aliases and middleware.

```
$middlewareRegistry->clear();
```

**Map**

Map an alias to middleware.

- `$alias` is a string representing the middleware alias.
- `$middleware` is a string representing the [*Middleware*](#middleware) class name, or a closure that returns an instance of a [*Middleware*](middleware) class.
- `$arguments` is an array containing additional arguments for creating the [*Middleware*](#middleware), and will default to *\[\]*.

```
$middlewareRegistry->map($alias, $middleware, $arguments);
```

**Resolve**

Resolve [*Middleware*](#middleware).

- `$middleware` is a [*Middleware*](#middleware) class instance, class name, alias or *Closure*.

```
$resolvedMiddleware = $middlewareRegistry->resolve($middleware);
```

You can pass additional arguments to the `handle` method of the [*Middleware*](#middleware) by appending a colon followed by a comma-separated list of arguments to the string.

```
$middlewareRegistry->resolve('alias:arg1,arg2');
```

[*Middleware*](#middleware) dependencies will be resolved automatically from the [*Container*](https://github.com/elusivecodes/FyreContainer).

**Use**

Load a shared [*Middleware*](#middleware) instance.

- `$alias` is a string representing the middleware alias.

```
$middleware = $middlewareRegistry->use($alias);
```

[*Middleware*](#middleware) dependencies will be resolved automatically from the [*Container*](https://github.com/elusivecodes/FyreContainer).

Middleware Queues
-----------------

[](#middleware-queues)

```
use Fyre\Middleware\MiddlewareQueue;
```

- `$middlewares` is an array containing the [*Middleware*](#middleware).

```
$queue = new MiddlewareQueue($middlewares);
```

**Add**

Add [*Middleware*](#middleware).

- `$middleware` is a [*Middleware*](#middleware) class instance, class name name, alias or [*Closure*](#closures).

```
$queue->add($middleware);
```

**Count**

Get the [*Middleware*](#middleware) count.

```
$count = $queue->count();
```

**Current**

Get the [*Middleware*](#middleware) at the current index.

```
$middleware = $queue->current();
```

**Insert At**

Insert [*Middleware*](#middleware) at a specified index.

- `$index` is a number representing the index.
- `$middleware` is a [*Middleware*](#middleware) class instance, class name name, alias or [*Closure*](#closures).

```
$queue->insertAt($index, $middleware);
```

**Key**

Get the current index.

```
$key = $queue->key();
```

**Next**

Progress the index.

```
$queue->next();
```

**Prepend**

Prepend [*Middleware*](#middleware).

- `$middleware` is a [*Middleware*](#middleware) class instance, class name name, alias or [*Closure*](#closures).

```
$queue->prepend($middleware);
```

**Rewind**

Reset the index.

```
$queue->rewind();
```

**Valid**

Determine whether the current index is valid.

```
$valid = $queue->valid();
```

### Middleware

[](#middleware)

Custom middleware can be created by extending `\Fyre\Middleware\Middleware`, ensuring all below methods are implemented.

**Process**

Process a [*ServerRequest*](https://github.com/elusivecodes/FyreServer#server-requests).

- `$request` is a [*ServerRequest*](https://github.com/elusivecodes/FyreServer#server-requests).
- `$handler` is a [*RequestHandler*](#request-handlers).

```
$response = $middleware->process($request, $handler);
```

This method should call the `handle` method of the `$handler` with the `$request`, to handle the next middleware in the queue, then return the [*ClientResponse*](https://github.com/elusivecodes/FyreServer#client-responses).

### Closures

[](#closures)

You can also provide custom middleware as a simple *Closure*.

```
$middleware = function(ServerRequest $request, RequestHandler $handler): ClientResponse {
    return $handler->handle($request);
};
```

Request Handlers
----------------

[](#request-handlers)

```
use Fyre\Middleware\RequestHandler;
```

- `$container` is a [*Container*](https://github.com/elusivecodes/FyreContainer).
- `$middlewareRegistry` is a [*MiddlewareRegistry*](#basic-usage).
- `$queue` is a [*MiddlewareQueue*](#middleware-queues).
- `$initialResponse` is a [*ClientResponse*](https://github.com/elusivecodes/FyreServer#client-responses) to be used as the initial response, and will default to *null*.

```
$handler = new RequestHandler($container, $middlewareRegistry, $queue, $initialResponse);
```

Any dependencies will be injected automatically when loading from the [*Container*](https://github.com/elusivecodes/FyreContainer).

```
$handler = $container->use(RequestHandler::class, 'queue' => $queue);
```

If the `$initialResponse` is set to *null*, a new [*ClientResponse*](https://github.com/elusivecodes/FyreServer#client-responses) will be created.

**Handle**

Handle the next middleware in the queue.

- `$request` is a [*ServerRequest*](https://github.com/elusivecodes/FyreServer#server-requests).

```
$response = $handler->handle($request);
```

This method will return a [*ClientResponse*](https://github.com/elusivecodes/FyreServer#client-responses).

The provided `$request` will be automatically set as the [*ServerRequest*](https://github.com/elusivecodes/FyreServer#server-requests) instance in the [*Container*](https://github.com/elusivecodes/FyreContainer).

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance63

Regular maintenance activity

Popularity12

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity61

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

Recently: every ~33 days

Total

33

Last Release

224d ago

Major Versions

v2.2.2 → v3.02024-11-10

v3.0 → v4.02024-11-10

v4.0 → v5.02024-11-11

v5.0.1 → v6.02024-11-17

v6.0.9 → v7.02025-11-12

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

middlewarephpqueue

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[cakephp/cakephp

The CakePHP framework

8.8k19.1M1.7k](/packages/cakephp-cakephp)[typo3/cms

TYPO3 CMS is a free open source Content Management Framework initially created by Kasper Skaarhoj and licensed under GNU/GPL.

1.2k1.9M122](/packages/typo3-cms)[thecodingmachine/graphqlite

Write your GraphQL queries in simple to write controllers (using webonyx/graphql-php).

5733.2M40](/packages/thecodingmachine-graphqlite)[cakephp/authentication

Authentication plugin for CakePHP

1143.9M95](/packages/cakephp-authentication)[typo3/cms-core

TYPO3 CMS Core

3312.9M4.8k](/packages/typo3-cms-core)[cakephp/authorization

Authorization abstraction layer plugin for CakePHP

742.4M46](/packages/cakephp-authorization)

PHPackages © 2026

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