PHPackages                             ikkez/f3-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. ikkez/f3-middleware

ActiveLibrary[Framework](/categories/framework)

ikkez/f3-middleware
===================

A middleware router plugin for PHP Fat-Free Framework

v1.1.3(7y ago)2517.3k↓74.6%51GPL-3.0PHP

Since Jan 24Pushed 7y ago5 watchersCompare

[ Source](https://github.com/ikkez/f3-middleware)[ Packagist](https://packagist.org/packages/ikkez/f3-middleware)[ Docs](https://github.com/ikkez/f3-middleware)[ RSS](/packages/ikkez-f3-middleware/feed)WikiDiscussions master Synced today

READMEChangelog (3)DependenciesVersions (4)Used By (1)

[![Middleware](https://camo.githubusercontent.com/657d3545dad45f88a8bf1f073e39fcbe1660f80877058ca1814d74abfceb71e0/68747470733a2f2f696b6b657a2e64652f6c696e6b65642f66332d6d6964646c65776172652e706e67)](https://camo.githubusercontent.com/657d3545dad45f88a8bf1f073e39fcbe1660f80877058ca1814d74abfceb71e0/68747470733a2f2f696b6b657a2e64652f6c696e6b65642f66332d6d6964646c65776172652e706e67)

Middleware Router
-----------------

[](#middleware-router)

This is a middleware router for PHP Fat-Free-Framework, version 3.x

It's based on the F3 core router, that can be called independently before or after the main routing cycle. This can be useful if you want to hook into a group of other routes and want to do something right before processing the main route handler.

### Installation

[](#installation)

- Method 1: use composer composer require ikkez/f3-middleware
- Method 2: copy the `middleware.php` file into your F3 `lib/` directory or another directory that is known to the [AUTOLOADER](https://fatfreeframework.com/quick-reference#AUTOLOAD)

### Usage Samples

[](#usage-samples)

```
$f3 = require('lib/base.php');

// imagine you have some admin routes
$f3->route('GET|POST /admin','Controller\Admin->login');
// and these actions should be protected
$f3->route('GET|POST /admin/@action','Controller\Admin->@action');
$f3->route('GET|POST /admin/@action/@type','Controller\Admin->@action');
$f3->route('PUT /admin/upload','Controller\Files->upload');

// so just add a global pre-route to all at once
\Middleware::instance()->before('GET|POST /admin/*', function(\Base $f3, $params, $alias) {
	// do auth checks
});

\Middleware::instance()->run();
$f3->run();
```

Of course you could also use the `beforeroute` and `afterroute` events in your controller to add that auth check functionality. But in case your controller structure isn't ready yet for easy implementation or you have things you strictly want to separate from your controllers, like settings. Here the Middleware Router will aid you.

```
// enable the CORS settings only for your API routes:
\Middleware::instance()->before('GET|HEAD|POST|PUT|OPTIONS /api/*', function(\Base $f3) {
	$f3->set('CORS.origin','*');
});
```

You can also create additional middleware wrappers on other events:

```
$mw = \Middleware::instance();
$mw->on('limit',['GET @v1: /api/v1/*','GET @v2: /api/v2/*'], function($f3,$args,$alias) {
	// do api usage limit checks
	return false;
});

if ($mw->run('limit')) {
	// all good, continue
}else{
	// API limit reached
}
```

Notice
------

[](#notice)

Although you can probably use the middleware router as a completely stand alone router, it is not a full replacement of the frameworks integrated router. The middleware router does not include handling of route caching, header management or automated CORS support, so use it as an additional component for settings, checks and workload before/after the main routing cycle.

License
-------

[](#license)

You are allowed to use this plugin under the terms of the GNU General Public License version 3 or later.

Copyright (C) 2019 Christian Knuth (ikkez)

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity37

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 88.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 ~387 days

Total

3

Last Release

2672d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1177647?v=4)[Christian Knuth](/maintainers/ikkez)[@ikkez](https://github.com/ikkez)

---

Top Contributors

[![ikkez](https://avatars.githubusercontent.com/u/1177647?v=4)](https://github.com/ikkez "ikkez (8 commits)")[![christianmalek](https://avatars.githubusercontent.com/u/2873986?v=4)](https://github.com/christianmalek "christianmalek (1 commits)")

---

Tags

fat-free-frameworkmiddlewareroutermiddlewarerouterF3fatfree

### Embed Badge

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

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

###  Alternatives

[slim/slim

Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs

12.3k52.9M1.4k](/packages/slim-slim)[yiisoft/router

Yii router

62360.1k26](/packages/yiisoft-router)[ikkez/f3-assets

CSS/JS Assets Plugin for PHP Fat-Free Framework

3016.1k4](/packages/ikkez-f3-assets)

PHPackages © 2026

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