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

ActiveLibrary

geekmusclay/router
==================

A simple router, for learning and fun

0.6.1(1y ago)0401MITPHPPHP ^8.0

Since Sep 23Pushed 1y ago1 watchersCompare

[ Source](https://github.com/geekmusclay/router)[ Packagist](https://packagist.org/packages/geekmusclay/router)[ RSS](/packages/geekmusclay-router/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (9)Versions (17)Used By (1)

GeekMusclay Router
==================

[](#geekmusclay-router)

Setup
-----

[](#setup)

Simply clone this pckage and run `composer install` command.

> **/!\\ WARNING** This package require `geekmusclay/di-container` currently under development To use this package you will have to donwload it, adn require it locally

Getting started
---------------

[](#getting-started)

```
declare(strict_types=1);

require '../vendor/autoload.php';

use Geekmusclay\DI\Core\Container;
use GuzzleHttp\Psr7\ServerRequest;
use Geekmusclay\Router\Core\Router;
use Psr\Http\Message\ServerRequestInterface;

$container = new Container();
$router = new Router($container);

$router->get('/', function (ServerRequestInterface $request): void {
    var_dump($request->getQueryParams());
    echo 'Hello World !';
});

$router->get('/hello', function (ServerRequestInterface $request): void {
    $name = $request->getQueryParams()['name'] ?? null;
    if (null === $name) {
        echo 'Hello World !';
    } else {
        echo 'Hello ' . $name . ' !';
    }
});

try {
    $router->run(ServerRequest::fromGlobals());
} catch (Exception $e) {
    die($e->getMessage());
}
```

Routing
-------

[](#routing)

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

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

$router->put('/put', function () {
    echo 'PUT route';
});

$router->delete('/delete', function () {
    echo 'DELETE route';
});
```

Group routes
------------

[](#group-routes)

```
$router->group('/api/v1', function (RouterInterface $group) use ($router) {

    $group->get('/', function () {
        echo 'Welcome on api !';
    }, 'api.v1.index');

    $group->get('/coucou', function () {
        echo 'Coucou';
    }, 'api.v1.coucou');

    $group->get('/:id', function (int $id) {
        echo 'Coucou n°' . $id;
    }, 'api.v1.coucou.detail')->with([
        'id' => '[0-9]+',
    ]);

    $group->group('/sub', function (RouterInterface $subgroup) use ($router) {

        $subgroup->get('/', function () use ($router) {
            echo 'Sub index : ' . $router->path('api.v1.sub.index');
        }, 'api.v1.sub.index');

        $subgroup->get('/test', function () {
            echo 'Sub test';
        }, 'api.v1.sub.test');

        $subgroup->get('/:id', function (int $id) {
            echo 'Sub n°' . $id;
        }, 'api.v1.sub.detail')->with([
            'id' => '[0-9]+',
        ]);

    });

});
```

Using PHP 8 attributes
----------------------

[](#using-php-8-attributes)

```
$router->register(MyController::class);
```

```
use Geekmusclay\Router\Attribute\Route;
use Psr\Http\Message\ServerRequestInterface as Request;

#[Route(path: '/prefixed')]
class MyController
{
    #[Route(path: '/', name: 'fake.index')]
    public function index()
    {
        return 'Index';
    }

    #[Route(path: '/hello', name: 'fake.hello')]
    public function hello()
    {
        return 'Hello';
    }

    #[Route(path: '/static', name: 'fake.static')]
    public static function staticHello()
    {
        return 'Hello';
    }

    #[Route(path: '/:id-:slug', name: 'fake.complex', with: [
        'id' => '[0-9]+',
        'slug' => '[a-z\-]+'
    ])]
    public function complex(Request $request, int $id, string $slug)
    {
        return 'Method: ' . $request->getMethod() . ', Id: ' . $id . ', Slug: ' . $slug;
    }
}
```

License
-------

[](#license)

This package is under MIT licence.

**Have fun!**

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance44

Moderate activity, may be stable

Popularity8

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 87.5% 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 ~73 days

Recently: every ~170 days

Total

13

Last Release

444d ago

### Community

Maintainers

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

---

Top Contributors

[![cedricvsi](https://avatars.githubusercontent.com/u/210379029?v=4)](https://github.com/cedricvsi "cedricvsi (42 commits)")[![geekmusclay](https://avatars.githubusercontent.com/u/113786478?v=4)](https://github.com/geekmusclay "geekmusclay (6 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[laravel/reverb

Laravel Reverb provides a real-time WebSocket communication backend for Laravel applications.

1.5k9.4M48](/packages/laravel-reverb)[neos/flow-development-collection

Flow packages in a joined repository for pull requests.

144179.3k3](/packages/neos-flow-development-collection)[php-heroku-client/php-heroku-client

A PHP client for the Heroku Platform API

24404.8k4](/packages/php-heroku-client-php-heroku-client)[onesignal/onesignal-php-api

A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com

34170.2k2](/packages/onesignal-onesignal-php-api)

PHPackages © 2026

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