PHPackages                             stefanobalocco/damnsmallrouter - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. stefanobalocco/damnsmallrouter

ActiveLibrary[HTTP &amp; Networking](/categories/http)

stefanobalocco/damnsmallrouter
==============================

A really simple and small pathinfo php router

1.0.4(1y ago)091BSD-3-ClausePHP

Since May 10Pushed 10mo ago1 watchersCompare

[ Source](https://github.com/StefanoBalocco/DamnSmallRouter)[ Packagist](https://packagist.org/packages/stefanobalocco/damnsmallrouter)[ Docs](https://github.com/StefanoBalocco/DamnSmallRouter)[ RSS](/packages/stefanobalocco-damnsmallrouter/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (3)DependenciesVersions (6)Used By (0)

DamnSmallRouter
===============

[](#damnsmallrouter)

A really simple and small pathinfo php router

Installation
------------

[](#installation)

Install via Composer:

```
composer require stefanobalocco/damnsmallrouter
```

Or add to `composer.json`:

```
{
    "require": {
        "stefanobalocco/damnsmallrouter": "^1.0"
    }
}
```

Run `composer install` or `composer update`.

Basic Usage
-----------

[](#basic-usage)

### Initialization

[](#initialization)

```
use StefanoBalocco\DamnSmallRouter\Router;
$router = new Router();
```

### Adding Routes

[](#adding-routes)

```
// Simple route with numeric placeholder
$router->AddRoute(
    '/user/#09#',                   // Route pattern
    function($userId) {             // Callback - pattern parameters
        $user = getUserFromDatabase($userId);
        return renderUserProfile($user);
    },
    [],                             // Additional variables (optional)
    'GET',                          // HTTP method (default: GET)
    $isAuthorized                   // Route availability (optional)
);

// Route with additional variables
// Note: $variables are passed BEFORE pattern parameters
$router->AddRoute(
    '/user/#09#',
    function($isLogged, $userId) {  // $isLogged from $variables, $userId from pattern
        if (!$isLogged) {
            return redirect('/login');
        }
        $user = getUserFromDatabase($userId);
        return renderUserProfile($user);
    },
    [ isLogged() ]                  // This array becomes the first parameters
);

// Multiple methods for same route
$router->AddRoute('/profile', $profileGetHandler, [], 'GET');
$router->AddRoute('/profile', $profileUpdateHandler, [], 'POST');

// Conditional route availability
$router->AddRoute('/admin', $adminHandler, [], 'GET', userIsAdmin());
```

### Error Handling

[](#error-handling)

Default error routes set HTTP response codes and return null. Customize them:

```
$router->AddRoute403(function() {
    http_response_code(403);
    return renderErrorPage("Access forbidden", 403);
});

$router->AddRoute404(function() {
    http_response_code(404);
    return renderErrorPage("Page not found", 404);
});

$router->AddRoute405(function() {
    http_response_code(405);
    return renderErrorPage("Method not allowed", 405);
});

$router->AddRoute500(function() {
    http_response_code(500);
    return renderErrorPage("Internal server error", 500);
});
```

### Router Execution

[](#router-execution)

```
echo $router->Route(); // Display the routed page
```

Key Features
------------

[](#key-features)

- Pattern matching with placeholder support
- Support for multiple HTTP methods
- Customizable error handling with automatic status codes
- Automatic HEAD request handling (converted to GET)

Available Placeholders
----------------------

[](#available-placeholders)

- `#09#`: Numbers (`\d+`)
- `#AZ#`: Letters (`[a-zA-Z]+`)
- `#AZ09#`: Alphanumeric characters (`[\w]+`)

Methods
-------

[](#methods)

### `AddRoute($route, $callback, $variables = [], $method = 'GET', $available = null)`

[](#addrouteroute-callback-variables---method--get-available--null)

Adds a new route with:

- `$route`: URL pattern with placeholders
- `$callback`: Function to execute (receives `$variables` first, then pattern matches)
- `$variables`: Additional variables passed as first parameters to callback
- `$method`: HTTP method (GET, POST, PUT, DELETE, etc.)
- `$available`: Boolean condition for route availability

### `RouteAvailable($method = 'GET', $withoutConditions = false)`

[](#routeavailablemethod--get-withoutconditions--false)

Checks if a route is available for the current path.

- `$method`: HTTP method to check
- `$withoutConditions`: If true, ignores the `$available` parameter of routes

### `Route()`

[](#route)

Executes routing for the current request and returns the callback result.

### Error Route Methods

[](#error-route-methods)

- `AddRoute403($callback, $variables = [])`: Sets handler for forbidden access
- `AddRoute404($callback, $variables = [])`: Sets handler for not found
- `AddRoute405($callback, $variables = [])`: Sets handler for method not allowed
- `AddRoute500($callback, $variables = [])`: Sets handler for internal server errors

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance47

Moderate activity, may be stable

Popularity5

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity59

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

Every ~414 days

Total

5

Last Release

539d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1469044?v=4)[Stefano Balocco](/maintainers/stefanobalocco)[@StefanoBalocco](https://github.com/StefanoBalocco)

---

Top Contributors

[![StefanoBalocco](https://avatars.githubusercontent.com/u/1469044?v=4)](https://github.com/StefanoBalocco "StefanoBalocco (24 commits)")

---

Tags

httppathinfophprouter

### Embed Badge

![Health badge](/badges/stefanobalocco-damnsmallrouter/health.svg)

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

###  Alternatives

[friendsofsymfony/rest-bundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony

2.8k73.3M319](/packages/friendsofsymfony-rest-bundle)[php-http/discovery

Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations

1.3k309.5M1.2k](/packages/php-http-discovery)[nyholm/psr7

A fast PHP7 implementation of PSR-7

1.3k235.4M2.4k](/packages/nyholm-psr7)[pusher/pusher-php-server

Library for interacting with the Pusher REST API

1.5k94.8M293](/packages/pusher-pusher-php-server)[spatie/crawler

Crawl all internal links found on a website

2.8k16.3M52](/packages/spatie-crawler)[react/http

Event-driven, streaming HTTP client and server implementation for ReactPHP

78126.4M414](/packages/react-http)

PHPackages © 2026

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