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

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

kyleblanker/php-router
======================

PHP Router

v1.0.0(9y ago)013MITPHP

Since May 7Pushed 7y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

This is me just messing around, I probably wouldn't use this in a project

PHP Router
==========

[](#php-router)

A simple PHP router.

### Supported HTTP Methods

[](#supported-http-methods)

- GET
- POST
- PUT
- DELETE
- HEAD
- PATCH
- OPTIONS
- CONNECT

Examples
--------

[](#examples)

### Creating the router

[](#creating-the-router)

```
$router = new \KyleBlanker\Router();
```

### Creating a basic route

[](#creating-a-basic-route)

```
$router = new \KyleBlanker\Router();

$router->route('GET','/my-route',function(){
    echo 'This is my route';
});
```

### Route Variables

[](#route-variables)

Route variables are enclosed in `{}`.

```
$router = new \KyleBlanker\Router();

$router->route('GET','/my-route/{variable}',function($variable){
    echo 'This is my route variable ' . $variable;
});
```

### Routing Groups

[](#routing-groups)

Routing groups prefix the group path on the route path.

```
$router = new \KyleBlanker\Router();

$router->group('/my-group', function($router){
    $router->route('GET','/my-route',function(){
        echo 'This is my route';
    });
});
```

This will create a route with `/my-group/my-route`.

### Regular Expressions

[](#regular-expressions)

```
$router = new \KyleBlanker\Router();

$router->route('GET','/my-route/{id:/[^0-9]/}',function($id){
    echo 'This is my route';
});
```

This route will only allow the numbers 0-9 after /my-route The regular expressions key is defined from what's infront of the `:`

### Alternative route calls

[](#alternative-route-calls)

```
$router = new \KyleBlanker\Router();

$router->get('/get-route',function(){
    echo 'This is my get route';
});

$router->post('/post-route',function(){
    echo 'This is my post route';
});

$router->any('/any-route',function(){
    echo 'This is my any route';
});
```

The router is setup to allow you to call methods based on the HTTP methods supported. It also allows you to call `$router->any()` which will create a route for all the http methods supported.

### Dispatch the router

[](#dispatch-the-router)

```
$router = new \KyleBlanker\Router();

$router->route('GET','/my-route/{id:/[^0-9]/}',function($id){
    echo 'This is my route';
});

try
{
    $response = $router->dispatch($_SERVER['REQUEST_METHOD'],$_SERVER['REQUEST_URI']);
}
catch(\KyleBlanker\Routing\Exceptions\RouteNotFoundException $e)
{
    // A route was not found
}
catch(\KyleBlanker\Routing\Exceptions\MethodNotAllowedException $e)
{
    // A route was found, but the http method was not supported.
}

$route_handler = $response[Router::ROUTE_HANDLE];
$route_parameters = $response[Router::ROUTE_PARAMETERS];
```

If no match is found then `\KyleBlanker\Routing\Exceptions\RouteNotFoundException ` will be thrown. If a match is found but the route does not support that HTTP method then `\KyleBlanker\Routing\Exceptions\MethodNotAllowedException` will be thrown. The route handler can be what ever you want, a string to call some sort of controller controller or maybe a closure. This package will leave that up to you. The route parameters is an associative array with the keys being what were provided in the route path so `/my-route/{name}{id:/[^0-9]/}` might be `['name' => 'kyle', 'id' => 1]`.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

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

Unknown

Total

1

Last Release

3294d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/53d3790833f8effcfb908a13e417523d148bcc13cf5b083c5b3f6a55e9a9dbb1?d=identicon)[kyleblanker](/maintainers/kyleblanker)

---

Top Contributors

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

---

Tags

phprouter

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[imanghafoori/laravel-anypass

A minimal yet powerful package to help you in development.

21421.6k](/packages/imanghafoori-laravel-anypass)

PHPackages © 2026

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