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

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

roolith/router
==============

Simple PHP router

1.2.0(5mo ago)198[1 PRs](https://github.com/im4aLL/roolith-router/pulls)1MITPHPCI passing

Since Jul 18Pushed 4w ago2 watchersCompare

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

READMEChangelogDependencies (2)Versions (20)Used By (1)

Roolith router
--------------

[](#roolith-router)

A simple router class

### Install

[](#install)

```
composer require roolith/router

```

### Basic Usage

[](#basic-usage)

```
use Roolith\Route\Router;

require_once __DIR__ . '/PATH_TO_AUTOLOAD/autoload.php';

$router = new Router();
$router->setBaseUrl('http://localhost/your_project_root/');

$router->get('/', function() {
    return 'Roolith router';
});

$router->run();
```

#### More usage

[](#more-usage)

```
$router->get('/test', function() {
    return 'Test route';
});

$router->post('/test', function() {
    return 'post content';
});

$router->put('/test', function() {
    return 'put content';
});

$router->patch('/test', function() {
    return 'patch content';
});

$router->delete('/test', function() {
    return 'delete content';
});

$router->options('/test', function() {
    return 'options content';
});
```

#### Route param

[](#route-param)

```
$router->get('user/{id}', function($id) {
    return 'User id '.$id;
});

$router->get('/user/{userId}/edit/{another}', function($userId, $another) {
    return 'get content {userId}: '.$userId.' {another}: '.$another;
});
```

#### Multiple route at once

[](#multiple-route-at-once)

```
$router->get(['user', 'profile'], function() {
    return ['name' => 'John', 'age' => 45];
});
```

#### Multiple method at once

[](#multiple-method-at-once)

```
$router->match(['GET', 'POST'], '/user', function() {
    return 'GET POST content.';
});
```

#### Controller method

[](#controller-method)

```
$router->get('controller', 'Demo\Controller@index');
```

#### Named route

[](#named-route)

```
$router->get('controller', 'Demo\Controller@index')->name('controller.index');
```

#### Wildcard route

[](#wildcard-route)

```
$router->any('any', function() {
    return 'any content. Server request method:'. $_SERVER['REQUEST_METHOD'];
});
```

#### CRUD route

[](#crud-route)

```
$router->crud('/crud', function () {
    return 'crud content.';
});
```

Above example is equivalent to

```
$router->get('/crud', function() {})->name('crud.index');
$router->get('/crud/create', function() {})->name('crud.create');
$router->get('/crud/{item}', function() {})->name('crud.show');
$router->get('/crud/{item}/edit', function() {})->name('crud.edit');
$router->post('/crud', function() {})->name('crud.store');
$router->put('/crud/{item}', function() {})->name('crud.update');
$router->patch('/crud/{item}', function() {})->name('crud.update');
$router->delete('/crud/{item}', function() {})->name('crud.destroy');
```

If there is controller

```
$router->crud('/crud', 'Controller');
```

Above example is equivalent to

```
$router->get('/crud',               'Controller@index')->name('crud.index');
$router->get('/crud/create',        'Controller@create')->name('crud.create');
$router->get('/crud/{item}',        'Controller@show')->name('crud.show');
$router->get('/crud/{item}/edit',   'Controller@edit')->name('crud.edit');
$router->post('/crud',              'Controller@store')->name('crud.store');
$router->put('/crud/{item}',        'Controller@update')->name('crud.update');
$router->patch('/crud/{item}',      'Controller@update')->name('crud.update');
$router->delete('/crud/{item}',     'Controller@destroy')->name('crud.destroy');
```

#### Redirect route

[](#redirect-route)

```
$router->redirect('/redirect', '/redirected');
$router->redirect('/redirect', '/redirected', 302);
```

#### Optional param route

[](#optional-param-route)

```
$router->get('name/{name?}', function($name = 'Default name') {
    return "Your name is - $name";
});
```

#### Middleware

[](#middleware)

```
$router->get('/admin/dashboard', function() {
    return 'Dashboard content';
})->middleware(\Demo\AuthMiddleware::class);
```

#### Group route

[](#group-route)

```
$router->group(['middleware' => \Demo\AuthMiddleware::class, 'urlPrefix' => 'user/{userId}', 'namePrefix' => 'user.'], function () use ($router) {
    $router->get('profile', function ($userId){
        return "profile route: User id: $userId";
    })->name('profile');

    $router->get('action/{actionId}', function ($userId, $actionId){
        return "action route: User id: $userId and action id $actionId";
    })->name('action');
});
```

#### Get all route list

[](#get-all-route-list)

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

#### Get route url by name

[](#get-route-url-by-name)

```
$router->getUrlByName('controller.index');
```

#### For development

[](#for-development)

```
./vendor/bin/phpunit --testdox tests --stderr

```

Expected unit test result

```
Request
 ✔ Should get current url
 ✔ Should able to set base url
 ✔ Should get requested method
 ✔ Should get requested url without base url
 ✔ Should remove non allowed character from url string
 ✔ Should able to set and get request param

Response
 ✔ Should have header content type set to false
 ✔ Should able to set status code
 ✔ Should invoke once output html method if content is html
 ✔ Should invoke once output json method if content is array
 ✔ Should set json header
 ✔ Should set html header
 ✔ Should set plain header
 ✔ Should output json
 ✔ Should output html
 ✔ Should have error response
Something went wrong
Router
 ✔ Should initialize router array
 ✔ Should have group settings array
 ✔ Should able to set group settings
 ✔ Should able to reset group settings
 ✔ Should able to add get route
 ✔ Should able to add post route
 ✔ Should able to add put route
 ✔ Should able to add patch route
 ✔ Should able to add delete route
 ✔ Should able to add options route
 ✔ Should able to add multiple method route at once
 ✔ Should able to add wildcard route
 ✔ Should able to add crud route
 ✔ Should have default route for crud
 ✔ Should have create route for crud
 ✔ Should have show route for crud
 ✔ Should have edit route for crud
 ✔ Should have post route for crud
 ✔ Should have update route for crud
 ✔ Should have delete route for crud
 ✔ Should automatic define method name for controller for crud
 ✔ Should able to add redirect route
 ✔ Should able to group routes
 ✔ Should match router by path
 ✔ Should match router by pattern
 ✔ Should match pattern with given url
 ✔ Should add name to route
 ✔ Should get url by name
 ✔ Should add middleware to route
 ✔ Should route run call execute route method once

```

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance83

Actively maintained with recent releases

Popularity13

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 84.8% 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 ~122 days

Recently: every ~38 days

Total

17

Last Release

168d ago

### Community

Maintainers

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

---

Top Contributors

[![im4aLL](https://avatars.githubusercontent.com/u/1926302?v=4)](https://github.com/im4aLL "im4aLL (28 commits)")[![hadiAugmedix](https://avatars.githubusercontent.com/u/35101957?v=4)](https://github.com/hadiAugmedix "hadiAugmedix (5 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[infinum/eightshift-libs

WordPress libs developed by Eightshift team to use in modern WordPress.

63118.9k3](/packages/infinum-eightshift-libs)[drupal-code-builder/drupal-code-builder

Code generator for Drupal

27241.1k1](/packages/drupal-code-builder-drupal-code-builder)[php-di/zf1-bridge

Integrates PHP-DI to Zend Framework 1

27457.8k1](/packages/php-di-zf1-bridge)[sansec/composer-integrity-plugin

5624.2k1](/packages/sansec-composer-integrity-plugin)[php-di/symfony-bridge

Integrates PHP-DI to Symfony

17168.2k](/packages/php-di-symfony-bridge)[okapi/aop

PHP AOP is a PHP library that provides a powerful Aspect Oriented Programming (AOP) implementation for PHP.

3812.0k](/packages/okapi-aop)

PHPackages © 2026

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