PHPackages                             flatpixels/light-route - 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. [Framework](/categories/framework)
4. /
5. flatpixels/light-route

ActiveLibrary[Framework](/categories/framework)

flatpixels/light-route
======================

A simple php router easy to setup and use.

0.0.1(7y ago)091MITPHPPHP &gt;=7.2.0

Since Dec 27Pushed 7y ago1 watchersCompare

[ Source](https://github.com/Flat-Pixels/LightRoute-PHP)[ Packagist](https://packagist.org/packages/flatpixels/light-route)[ RSS](/packages/flatpixels-light-route/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (2)Versions (3)Used By (0)

Light-Route - A simple php router easy to setup and use
=======================================================

[](#light-route---a-simple-php-router-easy-to-setup-and-use)

This library provides a simple router configuration and its routes.

Install
=======

[](#install)

```
composer require flatpixels/light-route

```

Usage
=====

[](#usage)

First of all, you have to setup your routes by doing so:

- Get an instance of the Router:

```
$router = LightRoute\LightRouter::getInstance();
```

- Register your routes into the router:

```
$router->addRoute('get', '/posts/', function(){
    echo "Welcome to the posts page";
});
```

Now that you have configured your routes, you have to resolve the current user request URI by calling the resolver:

```
$router->resolve();
```

Register routes into the router
===============================

[](#register-routes-into-the-router)

Use the method `addRoute(string $requestMethod, $string requestUrl, callable $callable, [, string $routeName  ])` to add routes into the router. The method takes 4 arguments:

- `$requestMethod` : Set the user request method. only support: GET, POST.
- `$requestUrl` : Set the request url that will resolve the route.
- `$callable` : A callback that define the action to execute when the route is reached.
- `$routeName` : (Optional) set the name of the route.

Register routes with params
===========================

[](#register-routes-with-params)

You can register routes by passing datas into its url by using the notation `:paramName`. Example:

```
$route->addRoute('get', 'post/:id', function($id) {
    echo "Show the post: " . $id;
});
```

In the code below, i setup a route by passing the `id` into its url.

You can pass as much as data you want:

```
$route->addRoute('get', 'post/:id/:slug/:author', function($id, $slug, $author) {
    echo "Show the post: " . $id;
    echo "With the slug: " . $slug;
    echo "Written by: " . $author;
});
```

Routes with params validator
============================

[](#routes-with-params-validator)

By passing parameters into the route url, you can use the `format(array $paramsValidators)` method to set a validation constraint:

```
$route->addRoute('get', 'post/:id', function($id) {
    echo "Show the post: " . $id;
})->format(['id' => "[0-9]"]);
```

The `format(...)` method takes a pair `$key => $value` array where `$key` is a parmater name, and `$value` a regex that represents the valid values for this parameter.

Redirect to a specific route
============================

[](#redirect-to-a-specific-route)

You can use the router by calling the `redirect(..)` method, to redirect you to another route. The method takes 2 arguments:

- `$routeName` : The name of the route to which we must be redirected.
- `$params` : (Optional) An array of `$key => $value` where `$key` is a parmater name, and `$value` the value of the paramter:

```
$router->addRoute('get', '/go/to/single', function() use($router){

    //Redirect to the "single_post" route, with param: id=4
    $router->redirect('single_post', ['id' => 4]);
});
```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity47

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

2694d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/dedf1085a0bb2d80a23532afe9e1daf7bf9665b7b30e4dda0b9f55bd068dc2b0?d=identicon)[Flat-Pixels](/maintainers/Flat-Pixels)

---

Top Contributors

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

---

Tags

routesrouterphp-routerPhp routes

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/flatpixels-light-route/health.svg)

```
[![Health](https://phpackages.com/badges/flatpixels-light-route/health.svg)](https://phpackages.com/packages/flatpixels-light-route)
```

PHPackages © 2026

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