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(8y ago)07.0kMITPHPPHP &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 1mo 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 64% 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

3233d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/361d01dea838dfee1327e7c6e803e7f53ae92b48d6971bcaeca43d3d49504c19?d=identicon)[pwm](/maintainers/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

[friendsofsymfony/rest-bundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony

2.8k73.3M319](/packages/friendsofsymfony-rest-bundle)[php-http/discovery

Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations

1.3k309.5M1.2k](/packages/php-http-discovery)[nyholm/psr7

A fast PHP7 implementation of PSR-7

1.3k235.4M2.4k](/packages/nyholm-psr7)[pusher/pusher-php-server

Library for interacting with the Pusher REST API

1.5k94.8M291](/packages/pusher-pusher-php-server)[spatie/crawler

Crawl all internal links found on a website

2.8k16.3M52](/packages/spatie-crawler)[react/http

Event-driven, streaming HTTP client and server implementation for ReactPHP

78126.4M414](/packages/react-http)

PHPackages © 2026

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