PHPackages                             semperton/routing - 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. [Framework](/categories/framework)
4. /
5. semperton/routing

ActiveLibrary[Framework](/categories/framework)

semperton/routing
=================

The Semperton Routing component.

2.0.0(3y ago)089MITPHPPHP &gt;= 7.4

Since Jan 31Pushed 3y agoCompare

[ Source](https://github.com/semperton/routing)[ Packagist](https://packagist.org/packages/semperton/routing)[ RSS](/packages/semperton-routing/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (4)Dependencies (4)Versions (5)Used By (0)

[![Semperton](https://raw.githubusercontent.com/semperton/.github/main/readme-logo.svg)](https://github.com/semperton)Semperton Routing
=================

[](#semperton-routing)

A lightweight B-tree based routing library for PHP.
Supports custom validators and reverse routing.

---

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

[](#installation)

Just use Composer:

```
composer require semperton/routing

```

Routing requires PHP 7.4+

Routes
------

[](#routes)

All routes are added to a `RouteCollection`. There are shorthand functions for every http verb and a general `map()` method:

```
use Semperton\Routing\Collection\RouteCollection;

$routes = new RouteCollection();

$routes->map(['GET', 'POST'], '/blog/article/:id:d', 'article-handler');
$routes->get('/category/product', 'product-handler');
$routes->post('/user/login', 'login-handler');

// grouping

$routes->group('/blog', function (RouteCollection $blog) {
	$blog->get('/article', 'article-handler');
	$blog->get('/category', 'category-handler');
});
```

Matching
--------

[](#matching)

The `RouteMatcher` is used to match a request method and path against all defined routes. It uses the route tree from `RouteCollection` and returns a `MatchResult`:

```
use Semperton\Routing\Matcher\RouteMatcher;

$matcher = new RouteMatcher($routes);

$result = $matcher->match('GET', '/blog/article/3');

$result->isMatch(); // true
$result->getHandler(); // 'article-handler'
$result->getParams(); // ['id' => '3']
```

Placeholders
------------

[](#placeholders)

You can substitute parts of a route with placeholders. They start with a colon followed by an `identifier:validator` combination:

```
:path -- no validator
:id:d -- digit validator
:name:w -- word validator

```

Note that a placeholder MUST take up everything between two slashes e.g. `/blog/:category/:id:d`. Multiple substitutions like `/:document-:id.html` are not allowed. You should consider custom validators instead.

Wildcards
---------

[](#wildcards)

Wildcards can be used at the end of a route (catchall handler):

```
$routes->get('/*path', 'admin-handler');
$result = $matcher->match('GET', '/admin/users');
$result->getParams(); // ['path' => 'admin/users']
```

Note that wildcards are always evaluated last.

Validators
----------

[](#validators)

There are several builtin validators available:

```
:A -- ctype_alnum
:a -- ctype_alpha
:d -- ctype_digit
:x -- ctype_xdigit
:l -- ctype_lower
:u -- ctype_upper
:w -- ctype_alnum + _

```

You can add custom validators to the `RouteMatcher` for placeholder validation:

```
use Semperton\Routing\Collection\RouteCollection;
use Semperton\Routing\Matcher\RouteMatcher;

$routes = new RouteCollection();
$routes->get('/media/:filename:file', 'handler');

$matcher = new RouteMatcher($routes);
$matcher->setValidator('file', function (string $value) {

	$parts = explode('.', $value, 2);

	if(isset($parts[1])){
		return true;
	}

	return false;
});

$matcher->validate('readme.txt', 'file'); // true

$result = $matcher->match('GET', '/media/data.json');
$result->getParams(); // ['filename' => 'data.json']
```

Reverse Routing
---------------

[](#reverse-routing)

The `RouteCollection` can be used to build known routes with the `reverse()` method.

```
use Semperton\Routing\Collection\RouteCollection;

$routes = new RouteCollection();

// add a named route
$routes->get('/product/:id:d', 'product-route');

// build it
$routes->reverse('product-route', ['id' => 42]); // '/product/42'
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity56

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

Total

4

Last Release

1427d ago

Major Versions

1.0.2 → 2.0.02022-06-21

PHP version history (2 changes)1.0.2PHP &gt;= 7.2

2.0.0PHP &gt;= 7.4

### Community

Maintainers

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

---

Top Contributors

[![jrabausch](https://avatars.githubusercontent.com/u/38224080?v=4)](https://github.com/jrabausch "jrabausch (81 commits)")

---

Tags

b-tree-implementationphprouterroutingsemperton

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/semperton-routing/health.svg)

```
[![Health](https://phpackages.com/badges/semperton-routing/health.svg)](https://phpackages.com/packages/semperton-routing)
```

###  Alternatives

[symfony/symfony

The Symfony PHP framework

31.3k86.3M2.2k](/packages/symfony-symfony)[cakephp/cakephp

The CakePHP framework

8.8k18.5M1.6k](/packages/cakephp-cakephp)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[aimeos/aimeos-core

Full-featured e-commerce components for high performance online shops

4.5k346.9k48](/packages/aimeos-aimeos-core)[silverstripe/framework

The SilverStripe framework

7213.5M2.5k](/packages/silverstripe-framework)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)

PHPackages © 2026

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