PHPackages                             ajgarlag/psr15-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. [API Development](/categories/api)
4. /
5. ajgarlag/psr15-router

ActiveProject[API Development](/categories/api)

ajgarlag/psr15-router
=====================

Component to route PSR-7 requests through PSR-15 middlewares

0.5.3(2y ago)24.0k1MITPHPPHP &gt;=8.0CI failing

Since Jul 14Pushed 2y ago1 watchersCompare

[ Source](https://github.com/ajgarlag/psr15-router)[ Packagist](https://packagist.org/packages/ajgarlag/psr15-router)[ RSS](/packages/ajgarlag-psr15-router/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (9)Versions (11)Used By (0)

Psr15 Router
============

[](#psr15-router)

The Psr15 Router component allows you to route [PSR-7](http://www.php-fig.org/psr/psr-7/) requests through [PSR-15](https://www.php-fig.org/psr/psr-15/) middlewares.

[![Build Status](https://github.com/ajgarlag/psr15-router/actions/workflows/tests.yaml/badge.svg?branch=master)](https://github.com/ajgarlag/psr15-router/actions/workflows/tests.yaml)[![Latest Stable Version](https://camo.githubusercontent.com/da550a47f50484bf51e7a1af7e3357e6dbc8f4319930ba50e862c3a37a7baba2/68747470733a2f2f706f7365722e707567782e6f72672f616a6761726c61672f70737231352d726f757465722f762f737461626c652e706e67)](https://packagist.org/packages/ajgarlag/psr15-router)[![Latest Unstable Version](https://camo.githubusercontent.com/306aeda975b2ff0f2d566ba93bea70aaacc3aa5c0b22d68fdfc10f6899c1efdf/68747470733a2f2f706f7365722e707567782e6f72672f616a6761726c61672f70737231352d726f757465722f762f756e737461626c652e706e67)](https://packagist.org/packages/ajgarlag/psr15-router)[![Total Downloads](https://camo.githubusercontent.com/0035c508aee49a9420122d0adef8eb7f7392ae86c7147c9bc67fe1ba9992760c/68747470733a2f2f706f7365722e707567782e6f72672f616a6761726c61672f70737231352d726f757465722f646f776e6c6f6164732e706e67)](https://packagist.org/packages/ajgarlag/psr15-router)[![Montly Downloads](https://camo.githubusercontent.com/d76397cba74f3f4d1fce5784307d34db34600176f2fe2ea9db34ac10c8525701/68747470733a2f2f706f7365722e707567782e6f72672f616a6761726c61672f70737231352d726f757465722f642f6d6f6e74686c792e706e67)](https://packagist.org/packages/ajgarlag/psr15-router)[![Daily Downloads](https://camo.githubusercontent.com/1eed5759e99a7a3911faa2f1ccd314ff0f9e6a9e2abfe070442bf23f4ca3a62f/68747470733a2f2f706f7365722e707567782e6f72672f616a6761726c61672f70737231352d726f757465722f642f6461696c792e706e67)](https://packagist.org/packages/ajgarlag/psr15-router)[![License](https://camo.githubusercontent.com/db8de9cf006b77a8d0b2ecc5d13140eac2ccfdc3b61ee35e87e3ff8f1b71b94d/68747470733a2f2f706f7365722e707567782e6f72672f616a6761726c61672f70737231352d726f757465722f6c6963656e73652e706e67)](https://packagist.org/ajgarlag/psr15-router)

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

[](#installation)

To install the latest stable version of this component, open a console and execute the following command:

```
$ composer require ajgarlag/psr15-router

```

Usage
-----

[](#usage)

You can choose if you want to route your request through a [MiddlewareInterface](https://www.php-fig.org/psr/psr-15/#22-psrhttpservermiddlewareinterface) or a [RequestHandlerInterface](https://www.php-fig.org/psr/psr-15/#21-psrhttpserverrequesthandlerinterface)

### Middleware routing

[](#middleware-routing)

With this option, you has to build a `Router` to discriminate which middleware will process the request. Then build `RouterMiddleware` to process the request:

```
use Ajgarlag\Psr15\Router\Matcher\UriRegexRequestMatcher;
use Ajgarlag\Psr15\Router\Middleware\Route;
use Ajgarlag\Psr15\Router\Middleware\ArrayRouter;
use Ajgarlag\Psr15\Router\Middleware\RouterMiddleware;

$userMiddleware; //Some middleware to process user requests
$userRoute = new Route(
    new UriRegexRequestMatcher('^http(s)?://example.org/user/'),
    $userMiddleware
);
$adminMiddleware; //Some middleware to process admin requests
$adminRoute = new Route(
    new UriRegexRequestMatcher('^http(s)?://example.org/admin/'),
    $adminMiddleware
);

$router = new ArrayRouter();
$router->addRoute($userRoute);
$router->addRoute($adminRoute);

$routerMiddleware = new RouterMiddleware($router);

$response = $routerMiddleware->process($request, $requestHandler);
```

If the router does not return any middleware to process the request, it is processed directly through the request handler.

### Request handler routing

[](#request-handler-routing)

With this option, you has to build a `Router` to discriminate which request handler will process the request. Then build `RouterRequestHandler` to process the request. A failover request handler is required to process the request if the router cannot route the request. Usually this failover request handler should return a 404 response.

```
use Ajgarlag\Psr15\Router\Matcher\UriRegexRequestMatcher;
use Ajgarlag\Psr15\Router\RequestHandler\Route;
use Ajgarlag\Psr15\Router\RequestHandler\ArrayRouter;
use Ajgarlag\Psr15\Router\RequestHandler\RouterRequestHandler;

$userRequestHandler; //Some request handler to process user requests
$userRoute = new Route(
    new UriRegexRequestMatcher('^http(s)?://example.org/user/'),
    $userRequestHandler
);
$adminRequestHandler; //Some request handler to process admin requests
$adminRoute = new Route(
    new UriRegexRequestMatcher('^http(s)?://example.org/admin/'),
    $adminRequestHandler
);

$router = new ArrayRouter();
$router->addRoute($userRoute);
$router->addRoute($adminRoute);

$failoverRequestHandler; // Request handler that returns 404 unconditionally
$routerRequestHandler = new RouterRequestHandler($router, $failoverRequestHandler);

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

License
-------

[](#license)

This component is under the MIT license. See the complete license in the [LICENSE](LICENSE) file.

Reporting an issue or a feature request
---------------------------------------

[](#reporting-an-issue-or-a-feature-request)

Issues and feature requests are tracked in the [Github issue tracker](https://github.com/ajgarlag/psr15-router/issues).

Author Information
------------------

[](#author-information)

Developed with ♥ by [Antonio J. García Lagar](http://aj.garcialagar.es).

If you find this component useful, please add a ★ in the [GitHub repository page](https://github.com/ajgarlag/psr15-router) and/or the [Packagist package page](https://packagist.org/packages/ajgarlag/psr15-router).

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity64

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

Recently: every ~252 days

Total

9

Last Release

1046d ago

PHP version history (4 changes)0.1.0PHP &gt;=5.6.0

0.4.0PHP ^7.2

0.5.0PHP &gt;=7.4

0.5.2PHP &gt;=8.0

### Community

Maintainers

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

---

Top Contributors

[![ajgarlag](https://avatars.githubusercontent.com/u/388184?v=4)](https://github.com/ajgarlag "ajgarlag (35 commits)")

###  Code Quality

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ajgarlag-psr15-router/health.svg)

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

###  Alternatives

[symfony/symfony

The Symfony PHP framework

31.4k87.2M2.2k](/packages/symfony-symfony)[cakephp/cakephp

The CakePHP framework

8.9k19.5M1.8k](/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)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[thecodingmachine/graphqlite

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

5733.3M48](/packages/thecodingmachine-graphqlite)[moonshine/moonshine

Laravel administration panel

1.3k253.1k81](/packages/moonshine-moonshine)

PHPackages © 2026

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