PHPackages                             gnatsnapper/altorouter-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. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. gnatsnapper/altorouter-middleware

ActiveLibrary[PSR &amp; Standards](/categories/psr-standards)

gnatsnapper/altorouter-middleware
=================================

A PSR-15 Middleware to allow the use of the venerable AltoRouter in Middleware-based PHP applications

v0.0.2(5y ago)034GPL-3.0-or-laterPHPPHP ^7.3CI failing

Since Aug 13Pushed 5y ago1 watchersCompare

[ Source](https://github.com/gnatsnapper/altorouter-middleware)[ Packagist](https://packagist.org/packages/gnatsnapper/altorouter-middleware)[ RSS](/packages/gnatsnapper-altorouter-middleware/feed)WikiDiscussions master Synced 5d ago

READMEChangelog (1)Dependencies (8)Versions (3)Used By (0)

[![Build Status](https://camo.githubusercontent.com/739cb20eef59c3f8c9eaf2ef7eb8aefd8bccf117843aff997190e6021ec3355b/68747470733a2f2f7472617669732d63692e6f72672f676e6174736e61707065722f616c746f726f757465722d6d6964646c65776172652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/gnatsnapper/altorouter-middleware)[![PHP Composer](https://github.com/gnatsnapper/altorouter-middleware/workflows/PHP%20Composer/badge.svg)](https://github.com/gnatsnapper/altorouter-middleware/workflows/PHP%20Composer/badge.svg)

AltoRouter Middleware
=====================

[](#altorouter-middleware)

Install
-------

[](#install)

```
composer require gnatsnapper/altorouter-middleware

```

Usage
-----

[](#usage)

This class simply extends the venerable [AltoRouter](https://github.com/dannyvankooten/AltoRouter) class to allow use as a router/dispatcher. If a route is not found the request is passed to the next middleware. If a route is mapped the AltoRouter will produce a response, therefore the route must be a callable returning an object implementing Psr\\Http\\Message\\ResponseInterface.

```
$altorouter = new AltoRouterMiddleware();

//map array of routes

$altorouter->addRoutes(
[
    [
        'GET',
        '/',
        function () {
             $r = new Response();
             $r->getBody()->write('home');
             return $r;
        }
    ],
    [
        'GET',
        '/users',
        function () {
             $r = new Response();
             $r->getBody()->write('users');
             return $r;
        }
    ]

]
);

//or map single route

$altorouter->map(
        'GET',
        '/admin',
        function () {
             $r = new Response();
             $r->getBody()->write('admin');
             return $r;
        }
    );
```

Then add this middleware to the applications middleware pipeline.

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

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

Total

2

Last Release

2100d ago

### Community

Maintainers

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

---

Top Contributors

[![gnatsnapper](https://avatars.githubusercontent.com/u/25196390?v=4)](https://github.com/gnatsnapper "gnatsnapper (18 commits)")

---

Tags

psrmiddlewarepsr-15

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[mezzio/mezzio

PSR-15 Middleware Microframework

3883.6M97](/packages/mezzio-mezzio)[mezzio/mezzio-authentication

Authentication middleware for Mezzio and PSR-7 applications

121.6M26](/packages/mezzio-mezzio-authentication)[jimtools/jwt-auth

PSR-15 JWT Authentication middleware, A replacement for tuupola/slim-jwt-auth

20142.3k3](/packages/jimtools-jwt-auth)

PHPackages © 2026

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