lukman-ss/router

A lightweight and flexible routing library for PHP 8.2+.

Maintainers

Package info

github.com/lukman-ss/router

pkg:composer/lukman-ss/router

Statistics

Installs: 3

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.1 2026-06-13 08:38 UTC

This package is auto-updated.

Last update: 2026-06-13 08:48:51 UTC


README

Lukman Router Hero

Lightweight routing package for PHP 8.2+ built on lukman-ss/http.

Features

  • HTTP route registration for GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD, any(), and match().
  • Static and dynamic route matching with where() constraints.
  • Route groups with prefix, name prefix, and middleware.
  • Handler dispatch for closures, array callables, and Class@method.
  • Middleware pipeline using Lukman\Http\MiddlewareInterface.
  • URL generation for named routes.

Installation

composer require lukman-ss/router

Usage

<?php

declare(strict_types=1);

use Lukman\Http\Request;
use Lukman\Http\Response;
use Lukman\Router\Router;

$router = new Router();

$router->get('/users/{id}', function (Request $request, string $id): Response {
    return new Response('User ' . $id);
})->where('id', '[0-9]+')->name('users.show');

$response = $router->dispatch(new Request('GET', '/users/42'));

echo $response->content();

Groups

<?php

declare(strict_types=1);

use Lukman\Router\Router;

$router = new Router();

$router->group([
    'prefix' => '/api',
    'name' => 'api.',
    'middleware' => App\Http\Middleware\AuthMiddleware::class,
], function (Router $router): void {
    $router->get('/users/{id}', App\Http\Controller\UserController::class . '@show')
        ->name('users.show');
});

$url = $router->url('api.users.show', ['id' => 42, 'tab' => 'profile']);
// /api/users/42?tab=profile

Running Tests

composer test