PHPackages                             slabphp/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. slabphp/router

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

slabphp/router
==============

SlabPHP Router

v0.1.6(8y ago)0601Apache-2.0PHP

Since Feb 11Pushed 7y ago1 watchersCompare

[ Source](https://github.com/SlabPHP/router)[ Packagist](https://packagist.org/packages/slabphp/router)[ Docs](https://www.salernolabs.com/slab)[ RSS](/packages/slabphp-router/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (3)Versions (8)Used By (1)

SlabPHP Router
==============

[](#slabphp-router)

This router library will take specially crafted XML files, build a routing table, and determine if a route can be matched to the current REQUEST\_URI parameters.

This router probably pales in comparison to many other modern open source routers. We're well aware XML is in many cases frowned upon. This library was written many years ago. Please see the main SlabPHP documentation for more information about this and all SlabPHP libraries.

Router Setup and Usage
----------------------

[](#router-setup-and-usage)

First import the library

```
composer require slabphp/router

```

Then configure and instantiate your router.

```
$configuration = new \Slab\Router\Configuration();

$configuration
    ->setConfigurationPaths('/framework/configs','/site/configs'])
    ->addRouteFile('default.xml');

$router = new \Slab\Router($configuration);

```

Next write your route files and resolve some routes!

```
$router->determineSelectedRoute();
$route = $router->getSelectedRoute();

```

Based on the values of $\_SERVER\['REQUEST\_URI'\] and the routes in /framework/configs/default.xml and /site/configs/default.xml, you will either get false (a 404 condition) or a \\Slab\\Router\\Route object.

Route Creation
--------------

[](#route-creation)

### Static Routes

[](#static-routes)

Depending on how you configure the router, a route file may be anywhere. But here is an example of a route file:

```

        /
        Homepage
        \Namespace\Path\To\Your\Controller

```

### Dynamic Routes (Pattern Validation)

[](#dynamic-routes-pattern-validation)

You can also have dynamic routes that use pattern validators. For example:

```

    /something
    A Dynamic URL Path
    \Some\Controller
    /value/{string:someVar}/thing/{numeric:intVar}

        1
        string

```

This would match a URL that comes in looking like */something/value/my-first-string/thing/32* Notice the *{string:someVar}* and *{numeric:intVar}*. These are mechanisms that tell the SlabPHP router to use a specific validator class and the variable name to store it in. You can create your own custom validators and simply specify their entire classname. For example, a blog post may have something like this:

```

    Blog URL
    \Some\Controller
    /
    /{numeric:year}}/{numeric:month}/{\My\Blog\Router\Validators\PostSlug:postSlug}

        1
        string

```

As long as \\My\\Blog\\Router\\Validators\\PostSlug implements the correct interface, and returns true/false, you can fail this route if the post slug is wrong.

There are some built-in validators but many are application specific.

- **string** - will match a string with a set of characters; a-z, 0-9, underscore, plus +, and a space.
- **date** - will match any date that will work in the constructor to new \\DateTime()
- **numeric** - will match a number
- **value** - matches an exact value, this is used internally for specific url segment values in pattern fields
- **any** - matches anything

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

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

Total

7

Last Release

3015d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/155974?v=4)[Eric Salerno](/maintainers/ericsalerno)[@ericsalerno](https://github.com/ericsalerno)

---

Top Contributors

[![ericsalerno](https://avatars.githubusercontent.com/u/155974?v=4)](https://github.com/ericsalerno "ericsalerno (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[ecotone/ecotone

Supporting you in building DDD, CQRS, Event Sourcing applications with ease.

558549.8k17](/packages/ecotone-ecotone)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k20](/packages/civicrm-civicrm-core)[j0k3r/php-readability

Automatic article extraction from HTML

186808.8k6](/packages/j0k3r-php-readability)[symfony/ai-platform

PHP library for interacting with AI platform provider.

51927.7k136](/packages/symfony-ai-platform)[symfony/ai-agent

PHP library for building agentic applications.

30536.7k44](/packages/symfony-ai-agent)[spomky-labs/pwa-bundle

Progressive Web App Manifest Generator Bundle for Symfony.

6144.4k1](/packages/spomky-labs-pwa-bundle)

PHPackages © 2026

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