PHPackages                             pwm/sfw-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. pwm/sfw-router

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

pwm/sfw-router
==============

A simple Router that maps incoming requests to predefined handlers

1.1.0(9y ago)07.1kMITPHPPHP &gt;=7.1.0

Since Apr 27Pushed 8y ago1 watchersCompare

[ Source](https://github.com/pwm/sfw-router)[ Packagist](https://packagist.org/packages/pwm/sfw-router)[ RSS](/packages/pwm-sfw-router/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (2)Versions (3)Used By (0)

SFW Router
==========

[](#sfw-router)

[![Build Status](https://camo.githubusercontent.com/0cf639d8b78408b1471e018a2fe1e1bb5593813b7c6d2bfa6461faffb106a4c2/68747470733a2f2f7472617669732d63692e6f72672f70776d2f7366772d726f757465722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/pwm/sfw-router)[![codecov](https://camo.githubusercontent.com/8b68994cd29fac0ee8b8ab1aa75d29e712ee129685daddeb8ded3f35c0811a08/68747470733a2f2f636f6465636f762e696f2f67682f70776d2f7366772d726f757465722f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/pwm/sfw-router)[![Maintainability](https://camo.githubusercontent.com/b067db2913bc8ace218461cb251515cccc813d4d942f754f4fb8d7b8aee0fbe8/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f35336232366365376638366166343630643030372f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/pwm/sfw-router/maintainability)[![Test Coverage](https://camo.githubusercontent.com/1585bac783d8ef6024f458c6f04280691ae5ad124f3a69aa56b36610f4c9f762/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f35336232366365376638366166343630643030372f746573745f636f766572616765)](https://codeclimate.com/github/pwm/sfw-router/test_coverage)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)

A simple Router that maps incoming requests to predefined handlers.

It builds a tree using segments of a predefined uri as internal nodes and its corresponding handler as the terminal node. It resolves routes by traversing this tree.

Wildcard segments are supported and captured for use in the handler. See usage for more detail.

Exact segment match wins over wildcard match. Eg. if you have `/foo/bar` and `/foo/{x}` defined as routes with corresponding handlers `Bar` and `X` then `/foo/bar` will be handled by `Bar` while `/foo/baz` will be handled by `X`.

Table of Contents
-----------------

[](#table-of-contents)

- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)
- [How it works](#how-it-works)
- [Tests](#tests)
- [Changelog](#changelog)
- [Licence](#licence)

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

[](#requirements)

PHP 7.1+

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

[](#installation)

```
composer require pwm/sfw-router

```

Usage
-----

[](#usage)

```
// Router depends on Request
use SFW\Request\Request;
use SFW\Request\RequestMethod as Method;
use SFW\Request\RequestUri as Uri;

// Have some controllers
class FooCtrl
{
    public function getAll(Request $request): array { /* ... */ }
    public function post(Request $request): bool { /* ... */ }
}
class BarCtrl
{
    public function getById(Request $request, $fooId, $barId): Bar { /* ... */ }
}

// Create router
$router = new Router();

// Add routes and corresponding route handlers
$router->add(new Route(new Method(Method::GET), new Uri('/foo')), new RouteHandler(FooCtrl::class, 'getAll'));
$router->add(new Route(new Method(Method::POST), new Uri('/foo')), new RouteHandler(FooCtrl::class, 'post'));
$router->add(new Route(new Method(Method::GET), new Uri('/foo/{id}/bar/{id}')), new RouteHandler(BarCtrl::class, 'getById'));

// Resolve a handler for an incoming request
$routeHandler = $router->resolve(new Route($request->getMethod(), $request->getUri()));

// (Optional) Resolve the handler class from the container and call the handling method
$response = $container
    ->resolve($routeHandler->getClassName())
    ->{$routeHandler->getMethodName()}($request, ...$routeHandler->getRoute()->getCapturedSegments());
```

How it works
------------

[](#how-it-works)

TBD

Tests
-----

[](#tests)

```
$ vendor/bin/phpunit
$ composer phpcs
$ composer phpstan

```

Changelog
---------

[](#changelog)

[Click here](changelog.md)

Licence
-------

[](#licence)

[MIT](LICENSE)

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

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

Total

2

Last Release

3287d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/195513?v=4)[Zsolt Szende](/maintainers/pwm)[@pwm](https://github.com/pwm)

---

Top Contributors

[![pwm](https://avatars.githubusercontent.com/u/195513?v=4)](https://github.com/pwm "pwm (15 commits)")

---

Tags

http-routersfw

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/pwm-sfw-router/health.svg)

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

###  Alternatives

[php-http/cache-plugin

PSR-6 Cache plugin for HTTPlug

25126.1M82](/packages/php-http-cache-plugin)[illuminate/http

The Illuminate Http package.

11937.9M6.9k](/packages/illuminate-http)[rdkafka/rdkafka

A PHP extension for Kafka

2.2k24.3k1](/packages/rdkafka-rdkafka)[httpsoft/http-message

Strict and fast implementation of PSR-7 and PSR-17

87965.9k114](/packages/httpsoft-http-message)[mezzio/mezzio-router

Router subcomponent for Mezzio

265.4M92](/packages/mezzio-mezzio-router)[serpapi/google-search-results-php

Get Google, Bing, Baidu, Ebay, Yahoo, Yandex, Home depot, Naver, Apple, Duckduckgo, Youtube search results via SerpApi.com

69127.2k](/packages/serpapi-google-search-results-php)

PHPackages © 2026

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