PHPackages                             mattvb91/lightrouter - 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. mattvb91/lightrouter

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

mattvb91/lightrouter
====================

Lightweight Router

0.1.0(9y ago)25MITPHPPHP &gt;=7.1

Since Jun 28Pushed 9y ago1 watchersCompare

[ Source](https://github.com/mattvb91/LightRouter)[ Packagist](https://packagist.org/packages/mattvb91/lightrouter)[ RSS](/packages/mattvb91-lightrouter/feed)WikiDiscussions master Synced 4w ago

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

**LightRouter**

 [![](https://camo.githubusercontent.com/46b11314055a8f739b8cf994d4f9b554a5256fb22716d4ef9571476efd48a412/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6d617474766239312f4c69676874526f757465722f62616467652e7376673f6272616e63683d6d6173746572)](https://camo.githubusercontent.com/46b11314055a8f739b8cf994d4f9b554a5256fb22716d4ef9571476efd48a412/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6d617474766239312f4c69676874526f757465722f62616467652e7376673f6272616e63683d6d6173746572) [![](https://camo.githubusercontent.com/92f0575694eaa57ae7b85d633b83e27cb9f6ed055db6bda70a5f795ed4a1671e/68747470733a2f2f7472617669732d63692e6f72672f6d617474766239312f4c69676874526f757465722e7376673f6272616e63683d6d6173746572)](https://camo.githubusercontent.com/92f0575694eaa57ae7b85d633b83e27cb9f6ed055db6bda70a5f795ed4a1671e/68747470733a2f2f7472617669732d63692e6f72672f6d617474766239312f4c69676874526f757465722e7376673f6272616e63683d6d6173746572) [![](https://camo.githubusercontent.com/30fef78b0b20a0f387b0a75bc175b38c010e1f1ec59877bab84621896f197a3a/68747470733a2f2f706f7365722e707567782e6f72672f6d617474766239312f6c69676874726f757465722f762f737461626c65)](https://camo.githubusercontent.com/30fef78b0b20a0f387b0a75bc175b38c010e1f1ec59877bab84621896f197a3a/68747470733a2f2f706f7365722e707567782e6f72672f6d617474766239312f6c69676874726f757465722f762f737461626c65) [![](https://camo.githubusercontent.com/b27d3fb04d9605ed51f08dd82f657d90977aaf6c25b0c0329c39d57b557f2aec/68747470733a2f2f706f7365722e707567782e6f72672f6d617474766239312f6c69676874726f757465722f646f776e6c6f616473)](https://camo.githubusercontent.com/b27d3fb04d9605ed51f08dd82f657d90977aaf6c25b0c0329c39d57b557f2aec/68747470733a2f2f706f7365722e707567782e6f72672f6d617474766239312f6c69676874726f757465722f646f776e6c6f616473) [![](https://camo.githubusercontent.com/96d5987a41a6c9f79a566d943c83b4f8e4fdf2ac17618405bfdc50ec4c0f7f29/68747470733a2f2f706f7365722e707567782e6f72672f6d617474766239312f6c69676874726f757465722f762f756e737461626c65)](https://camo.githubusercontent.com/96d5987a41a6c9f79a566d943c83b4f8e4fdf2ac17618405bfdc50ec4c0f7f29/68747470733a2f2f706f7365722e707567782e6f72672f6d617474766239312f6c69676874726f757465722f762f756e737461626c65) [![](https://camo.githubusercontent.com/f7cd319079bfb6772a9e84eb7ae328808c46e346644cf54a097234d613989c63/68747470733a2f2f706f7365722e707567782e6f72672f6d617474766239312f6c69676874726f757465722f6c6963656e7365)](https://camo.githubusercontent.com/f7cd319079bfb6772a9e84eb7ae328808c46e346644cf54a097234d613989c63/68747470733a2f2f706f7365722e707567782e6f72672f6d617474766239312f6c69676874726f757465722f6c6963656e7365)

LightRouter
-----------

[](#lightrouter)

Lightweight PHP router class. This is a test project. If you need a reliable &amp; fully tested solution please check out FastRoute or AltoRouter.

### Basic Usage

[](#basic-usage)

```
$router = new mattvb91\LightRouter\Router();
$router->addRoute('/', MyController::class);
$router->run();
```

### Defining Routes

[](#defining-routes)

To add new routes use the `$router->addRoute()` method. If no action is defined it will default to `index` which will be needed on your controller.

You will need to pass the route path &amp; either a controller or a closure. If you do not specify an action it will default to 'index' which will be required on your controller.

```
$router->addRoute('/', MyController::class);
$router->addRoute('/contact', MyController::class, 'contact');

$route->addRoute('/hello', function() {
    echo 'Hello world';
});
```

### Defining parameters

[](#defining-parameters)

Passing parameters into your controller actions can be done using a `:parameter` attribute in your route definition:

```
$router->addRoute('/view/:param', MyController::class);
```

Your method parameter must match the defined route parameter. In our example above our controllers `view` method would look like this:

```
public function view($param)
{
}
```

### Automatically Injecting Models

[](#automatically-injecting-models)

If you are using the `LightModel` ORM package for your DB models you can automatically inject the associated model by specifying the instance type in your controller action:

```
//Your route definition
$router->addRoute('/user/view/:user', UserController::class, 'view');

//In your UserController::class
public function view(User $user)
{
    //$user is already fully loaded for you.
}
```

If you are using your own ORM or other DB model class you can also implement the `LightRouteModelInterface::class` in your custom model which expects you to return the fully loaded instance.

LightRouter will pass the associated $key from your route into the `getForLightRoute` method:

```
public class CustomModel implements LightRouteModelInterface
{
    public static function getForLightRoute($routeParam): LightRouteModelInterface
    {
        //Use $routeParam to load your model class and return the instance
    }
}
```

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

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

Unknown

Total

1

Last Release

3289d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

phpphp-libraryphp-routerphp7

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mattvb91-lightrouter/health.svg)

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

###  Alternatives

[yieldstudio/tailwind-merge-php

Merge Tailwind CSS classes without style conflicts

4974.6k1](/packages/yieldstudio-tailwind-merge-php)[access-manager/access-manager

The Hotspot Management System

605.2k](/packages/access-manager-access-manager)

PHPackages © 2026

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