PHPackages                             middlewares/aura-router - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. middlewares/aura-router

ActiveLibrary[HTTP &amp; Networking](/categories/http)

middlewares/aura-router
=======================

Middleware to use Aura.Router

v2.2.1(10mo ago)1110.9k↑66.7%23MITPHPPHP ^7.2 || ^8.0CI passing

Since Oct 2Pushed 10mo ago1 watchersCompare

[ Source](https://github.com/middlewares/aura-router)[ Packagist](https://packagist.org/packages/middlewares/aura-router)[ Docs](https://github.com/middlewares/aura-router)[ RSS](/packages/middlewares-aura-router/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (10)Versions (21)Used By (3)

middlewares/aura-router
=======================

[](#middlewaresaura-router)

[![Latest Version on Packagist](https://camo.githubusercontent.com/da78b308eaf7b25c1585dd0eb9c5e451f0d78258e1f9335b8365676b250ef811/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6964646c6577617265732f617572612d726f757465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/middlewares/aura-router)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Testing](https://github.com/middlewares/aura-router/workflows/testing/badge.svg)](https://github.com/middlewares/aura-router/workflows/testing/badge.svg)[![Total Downloads](https://camo.githubusercontent.com/cef711a8d3010f3ba862b53dddfd1e3fae8766e041f39fbea8acebd559c2723b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6964646c6577617265732f617572612d726f757465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/middlewares/aura-router)

Middleware to use [Aura.Router](https://github.com/auraphp/Aura.Router/) with a few more extras.

Requirements
------------

[](#requirements)

- PHP &gt;= 7.2
- A [PSR-7 http library](https://github.com/middlewares/awesome-psr15-middlewares#psr-7-implementations)
- A [PSR-15 middleware dispatcher](https://github.com/middlewares/awesome-psr15-middlewares#dispatcher)

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

[](#installation)

This package is installable and autoloadable via Composer as [middlewares/aura-router](https://packagist.org/packages/middlewares/aura-router).

```
composer require middlewares/aura-router
```

Example
-------

[](#example)

In this example, we are using [middleware/request-handler](https://github.com/middlewares/request-handler) to execute the route handler:

```
// Create the router
$router = new Aura\Router\RouterContainer();

$map = $router->getMap();

$map->get('hello', '/hello/{name}', function ($request) {

    // The route parameters are mapped to attributes
    $name = $request->getAttribute('name');

    // You can echo the output (it will be captured and wrote into the body)
    echo sprintf('Hello %s', $name);

    // Or return a string
    return sprintf('Hello %s', $name);

    // Or return a response
    return new Response();
});

$dispatcher = new Dispatcher([
    new Middlewares\AuraRouter($router),
    new Middlewares\RequestHandler()
]);

$response = $dispatcher->dispatch(new ServerRequest('/hello/world'));
```

**Aura.Router** allows to define anything as the router handler (a closure, callback, action object, controller class, etc.). The middleware will store this handler in a request attribute.

Usage
-----

[](#usage)

Create the middleware with a `Aura\Router\RouterContainer` instance:

```
$routerContainer = new Aura\Router\RouterContainer();

$route = new Middlewares\AuraRouter($routerContainer);
```

Optionally, you can provide a `Psr\Http\Message\ResponseFactoryInterface` as the second argument, that will be used to create the error responses (`404`, `405` or `406`). If it's not defined, [Middleware\\Utils\\Factory](https://github.com/middlewares/utils#factory) will be used to detect it automatically.

```
$routerContainer = new Aura\Router\RouterContainer();
$map = $router->getMap();
$map->get('list', '/users', 'listUsers')->extras(
    'key' => 'value'
]);

$optionalResponseFactory = new MyOwnResponseFactory();

$middleware = new Middlewares\AuraRouter($routerContainer, $optionalResponseFactory);

$dispatcher = new Dispatcher([
    // Hold the resolved route handler reference in an attribute called "handler"
    // (default: request-handler)
    $middleware->handlerAttribute('handler'),

    // Hold Aura's resolved route instance in an attribute called "aura-route"
    // (default: route)
    $middleware->routeAttribute('aura-route'),

    // Execute the route handler
    (new Middlewares\RequestHandler())->handlerAttribute('handler')
]);

// then, inside our Request Handler or Middleware
public function process(
    ServerRequestInterface $request,
    RequestHandlerInterface $handler
): ResponseInterface {
    /** @var string $handler this returns 'listUsers' */
    $handler = $request->getAttribute('handler');

    /** @var Route $route this returns the resolved Route instance */
    $route = $request->getAttribute('aura-route');

    // example to retrieve the previously set extra key/value "value"
    $route->extras['key'];

    // example to retrieve the route name "list"
    $route->name;
}
```

---

Please see [CHANGELOG](CHANGELOG.md) for more information about recent changes and [CONTRIBUTING](CONTRIBUTING.md) for contributing details.

The MIT License (MIT). Please see [LICENSE](LICENSE) for more information.

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance54

Moderate activity, may be stable

Popularity31

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor1

Top contributor holds 71.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 ~168 days

Recently: every ~420 days

Total

20

Last Release

312d ago

Major Versions

v0.9.0 → v1.0.02018-01-24

v1.1.0 → v2.x-dev2018-09-04

PHP version history (4 changes)v0.1.0PHP ^5.6 || ^7.0

v0.9.0PHP ^7.0

v2.0.0PHP ^7.2

v2.0.1PHP ^7.2 || ^8.0

### Community

Maintainers

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

![](https://www.gravatar.com/avatar/42e0d72f42eb7d84f67e20d28606da42e5a3248ca908b1eadb4366aafeae2561?d=identicon)[filisko](/maintainers/filisko)

---

Top Contributors

[![oscarotero](https://avatars.githubusercontent.com/u/377873?v=4)](https://github.com/oscarotero "oscarotero (69 commits)")[![filisko](https://avatars.githubusercontent.com/u/8798694?v=4)](https://github.com/filisko "filisko (26 commits)")[![kevinsmith](https://avatars.githubusercontent.com/u/397904?v=4)](https://github.com/kevinsmith "kevinsmith (1 commits)")

---

Tags

aurahttpmiddlewarepsr-15routerhttppsr-7middlewarerouterserverpsr-15aura

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/middlewares-aura-router/health.svg)

```
[![Health](https://phpackages.com/badges/middlewares-aura-router/health.svg)](https://phpackages.com/packages/middlewares-aura-router)
```

###  Alternatives

[middlewares/fast-route

Middleware to use FastRoute

96191.1k15](/packages/middlewares-fast-route)[middlewares/request-handler

Middleware to execute request handlers

451.6M26](/packages/middlewares-request-handler)[middlewares/negotiation

Middleware to implement content negotiation

47442.1k11](/packages/middlewares-negotiation)[middlewares/payload

Middleware to parse the body of the request with support for json, csv and url-encode

32466.8k17](/packages/middlewares-payload)[middlewares/http-authentication

Middleware to implement Basic and Digest Http authentication

35302.0k2](/packages/middlewares-http-authentication)[middlewares/whoops

Middleware to use Whoops as error handler

33205.4k24](/packages/middlewares-whoops)

PHPackages © 2026

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