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

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

wok/router
==========

WOK Router component

v0.4.1(9y ago)0571MIT

Since Sep 9Compare

[ Source](https://github.com/web-operational-kit/router)[ Packagist](https://packagist.org/packages/wok/router)[ RSS](/packages/wok-router/feed)WikiDiscussions Synced today

READMEChangelogDependencies (1)Versions (14)Used By (1)

Router
======

[](#router)

This library provides a leightweight router based on regular expressions.

[![SensioLabsInsight](https://camo.githubusercontent.com/0cf4647c71ebf48073e903cc15b806fa40461a406c107a61e1004d95c0c80a49/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f33353135656332302d316663342d343630332d383531622d3061656166323137653863342f6269672e706e67)](https://insight.sensiolabs.com/projects/3515ec20-1fc4-4603-851b-0aeaf217e8c4)

**Diclaimer** : This component is part of the WOK (Web Operational Kit) framework. It however can be used as a standalone library.

Install
-------

[](#install)

It is recommanded to install that component as a dependency using [Composer](https://getcomposer.org/) :

```
composer require wok/router

```

You're also free to get it with [git](https://git-scm.com/) or by [direct download](https://github.com/web-operational-kit/router/archive/master.zip) while this package has no dependencies.

```
git clone https://github.com/web-operational-kit/router.git

```

Features
--------

[](#features)

As any other router, these features are available :

- Routing with a method and a URI (see the [usage](#usage) section)
- Route Parameters replacing and matching
- Manipulating routes definition afterwards
- Retrieving routes meta data independently
- Routes collection manipulation

**Note :**Some features will not be implemented for now because of the wish of simplicity (and independance) of that library.

This is why the dispatcher does not execute any function. It only returns the first matching route with the information that would be needed.

Make your own opinion :)

Basic usage
-----------

[](#basic-usage)

```
use \WOK\Router\Route;
use \WOK\Router\Collection;

// First instanciate a collection
$collection = new Collection();

$collection = new Collection();
$collection->addRoute(
    new Route(
        ['POST', 'GET', 'HEAD'],// Define the accepted HTTP methods
        '/path/to/the/{resource}', // Define the route URI
        [ // Define the URI parameters
            'resource'  => '[a-z0-9\-]+'
        ]
    ),
    'Controller::action', // Define the target (function name, class, object, array, Closure, ...)
    'Controller->Action' // Define the route name
);

// Define many other routes ...

// Retrieve the first matching route
try {

    $route = $collection->match('GET', '/path/to/the/resource-file-name');

}

// No route match the current request
catch(\DomainException $e) {

    $route = (object) array(
        'name'          => 'Controller->pageNotFound',
        'action'        => ['Controller', 'pageNotFound'],
        'parameters'    => []
    );

}

// Play with the route value
call_user_func_array($route->action, $route->parameters);
```

**Warning:**To prevent any borring returned value the `Collection::match` throws a `DomainException` if no route is found.

That way, feel free to define any not found behavior

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity60

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

Recently: every ~30 days

Total

12

Last Release

3379d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2820221?v=4)[Sébastien ALEXANDRE](/maintainers/graphidev)[@graphidev](https://github.com/graphidev)

---

Top Contributors

[![graphidev](https://avatars.githubusercontent.com/u/2820221?v=4)](https://github.com/graphidev "graphidev (30 commits)")

### Embed Badge

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

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

###  Alternatives

[presseddigital/colorit

A slick color picker fieldtype plugin for the Craft CMS 3 control panel.

2032.4k](/packages/presseddigital-colorit)

PHPackages © 2026

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