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

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

bybzmt/router
=============

a fast php router

v1.0.3(4y ago)34711Apache-2.0PHPPHP &gt;=5.3.0

Since Oct 11Pushed 4y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (5)Used By (1)

Bybzmt/Router
=============

[](#bybzmtrouter)

A simple and fast PHP Router

Features
--------

[](#features)

- Static Route Patterns
- Dynamic Route Patterns
- Supports `GET`, `POST`, `PUT`, `DELETE`, `OPTIONS`, `PATCH` and `HEAD` request methods
- Supports `X-HTTP-Method-Override` header
- Allowance of `:Class.Method` calls
- Custom 404 handling
- Reverse Router

Prerequisites/Requirements
--------------------------

[](#prerequisitesrequirements)

- PHP 5.3 or greater
- URL Rewriting

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

[](#installation)

Installation is possible using Composer

```
composer require bybzmt/router

```

Usage
-----

[](#usage)

```
// Require composer autoloader
require __DIR__ . '/vendor/autoload.php';

// Create Router instance
$router = new \Bybzmt\Router\Router();

// Define routes
// ...

// Run it!
$router->run();
```

Routing
-------

[](#routing)

using $router-&gt;handle(method(s), pattern, function):

```
$router->handle('GET|POST', 'pattern', function() { … });
//or
$router->handle('GET|POST', 'pattern', ':Class.Method');
```

Shorthands for single request methods are provided:

```
$router->get('pattern', function() { /* ... */ });
$router->post('pattern', function() { /* ... */ });
$router->put('pattern', function() { /* ... */ });
$router->delete('pattern', function() { /* ... */ });
$router->options('pattern', function() { /* ... */ });
$router->patch('pattern', function() { /* ... */ });
//all methods
$router->all('pattern', function() { /* ... */ });
```

Route Patterns
--------------

[](#route-patterns)

- *Static Route Patterns* are essentially URIs, e.g. `/about`
- *Dynamic Route Patterns* are Perl-compatible regular expressions (PCRE) that resemble URIs, e.g. `/movies/(\d+)`

The subpatterns defined in Dynamic Route Patterns are converted to parameters which are passed into the route handling function. Prerequisite is that these subpatterns need to be defined as parenthesized subpatterns, which means that they should be wrapped between parens:

```
// Bad
$router->get('/hello/\w+', function($name) {
    echo 'Hello ' . htmlentities($name);
});

// Good
$router->get('/hello/(\w+)', function($name) {
    echo 'Hello ' . htmlentities($name);
});
```

:Class.Method calls
-------------------

[](#classmethod-calls)

We can route to the class action like so:

```
$router->get('/(\d+)', ':User.showProfile:id');
```

Custom 404
----------

[](#custom-404)

Override the default 404 handler using $router-&gt;set404(function);

```
$router->set404(function() {
    header('HTTP/1.1 404 Not Found');
    // ... do something special here
});
```

Reverse Router
--------------

[](#reverse-router)

```
$router = new \Bybzmt\Router\Router();
$router->get('/news/(\d+)', ':news.show:id');

$tool = new \Bybzmt\Router\Tool($router->getRoutes());
$data = $tool->convertReverse();

$reverse = new \Bybzmt\Router\Reverse($data);

//echo /news/1234
echo $reverse->buildUri('news.show', ['id'=>1234]);
```

Cache Data
----------

[](#cache-data)

Storage Data (file1.php)

```
$router = new \Bybzmt\Router\Router();
$router->get('/a1', ':example.test');
$router->get('/a2/(\d+)', ':example.test:k1');
$router->get('/a3/(\d+)/(\d+)', ':example.test:k1:k2');

$tool = new \Bybzmt\Router\Tool($router->getRoutes());

//Cache Router Data
$code = $tool->exportRoutes();
file_put_contents('routes_cache.php', $code);

//Cache Reverse Router Data
$code = $tool->exportReverse();
file_put_contents('reverse_cache.php', $code);
```

Recovery Data (file2.php)

```
//Recovery Router Data
$router = new \Bybzmt\Router\Router(require 'routes_cache.php');

//Recovery Reverse Router Data
$reverse = new \Bybzmt\Router\Reverse(require 'reverse_cache.php');
```

Thanks
------

[](#thanks)

- [bramus/router](https://github.com/bramus/router)
- [bephp/router](https://github.com/bephp/router)

Licence
-------

[](#licence)

Apache-2.0

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity61

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

Total

4

Last Release

1597d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/031f01c8296715e38460200b8706ce7a24808fdaacc2400a8e0075ddbd630670?d=identicon)[bybzmt](/maintainers/bybzmt)

---

Top Contributors

[![bybzmt](https://avatars.githubusercontent.com/u/1188099?v=4)](https://github.com/bybzmt "bybzmt (22 commits)")

---

Tags

router

### Embed Badge

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

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

###  Alternatives

[symfony/routing

Maps an HTTP request to a set of configuration variables

7.6k789.4M1.8k](/packages/symfony-routing)[nikic/fast-route

Fast request router for PHP

5.3k92.4M668](/packages/nikic-fast-route)[altorouter/altorouter

A lightning fast router for PHP

1.3k3.4M68](/packages/altorouter-altorouter)[league/route

Fast routing and dispatch component including PSR-15 middleware, built on top of FastRoute.

6633.1M115](/packages/league-route)[aura/router

Powerful, flexible web routing for PSR-7 requests.

5231.5M67](/packages/aura-router)[coffeecode/router

A classic CoffeeCode Router is easy, fast and extremely uncomplicated. Create and manage your routes in minutes!

181111.1k5](/packages/coffeecode-router)

PHPackages © 2026

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