PHPackages                             obscure-code/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. [Framework](/categories/framework)
4. /
5. obscure-code/router

ActiveLibrary[Framework](/categories/framework)

obscure-code/router
===================

PHP router

1.5(2y ago)020MITPHPPHP &gt;=8.0

Since Dec 30Pushed 2y ago1 watchersCompare

[ Source](https://github.com/obscure-code/router)[ Packagist](https://packagist.org/packages/obscure-code/router)[ RSS](/packages/obscure-code-router/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (6)Dependencies (6)Versions (7)Used By (0)

Requirements
------------

[](#requirements)

- PHP &gt;= 8.0
- [Composer](https://getcomposer.org/)

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

[](#installation)

```
$ composer require obscure-code/router

```

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

[](#basic-usage)

Create Router class:

```
use ObscureCode\Router as AbstractRouter;

class Router extends AbstractRouter {
    public function patternDefault(string $path): void
    {
        $this->load('header');
        $this->load($path);
        $this->load('footer');
    }

    public function patternBlank(string $path): void
    {
        $this->load($path);
    }

    public function patternError(string $path): void
    {
        http_response_code(404);
        $this->load('header');
        $this->load('error');
        $this->load('footer');
    }
};
```

Create config:

```
$config = [
    "index" => [
        "pattern" => "default",
    ],
    "ajax" => [
        "pattern" => "blank",
    ],
    "directory" => [
        "index" => [
            "pattern" => "default",
        ],
    ],
    "error" => [
        "pattern" => "error",
    ],
];
```

Create Router instance with root directory and config:

```
$router = new Router(
    __DIR__ . '/include',
    $config,
);
```

Examples:

```
// Call /include/index.php by default
$router->call('/');

// Call /include/directory/index.php
$router->call('/directory/index');

// If /include/a/b.php route exists, ['c', 'd', 'e'] will passed in $params
// If only /include/a.php exists, ['b', 'c', 'd', 'e'] will passed in $params
$router->call('/a/b/c/d/e');

// ['data'] will passed in $data
$router->call('/index', ['data']);
```

Also you can pass data in `load` method:

```
public function patternDefault(string $path): void
{
    $someClass = new SomeClass();

    $this->load('header');
    $this->load($path, ['someClass' => $someClass]);
    $this->load('footer');
}
```

If route not found in config, `NotFoundException` will be thrown. So you can use router like that:

```
use ObscureCode\Exceptions\NotFoundException;

try {
    ob_start();
    $router->call($route);
} catch (NotFoundException $exception) {
    ob_clean();
    $router->call('error');
} catch (SomeOtherException $exception) {
    // do something
} finally {
    ob_end_flush();
}
```

If route exist in config, but pattern or file not exists, `LogicException` will be thrown.

You can see an example of a boilerplate application [**here**](https://github.com/obscure-code/boilerplate).

Local development
=================

[](#local-development)

```
docker build --tag router .
docker run --detach -v "$(pwd):/app" --name=router router
docker exec -it router /bin/bash

composer install
composer tests
composer cs
composer stan
composer psalm

```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

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 ~127 days

Recently: every ~159 days

Total

6

Last Release

962d ago

PHP version history (2 changes)1.0PHP ^8.0

1.5PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/338a9e02bcd78a3031d090d13f3b3db633e08cc470bd68e3e4081199f1ffd072?d=identicon)[obscure-code](/maintainers/obscure-code)

---

Top Contributors

[![obscure-code](https://avatars.githubusercontent.com/u/52510132?v=4)](https://github.com/obscure-code "obscure-code (4 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[laravel/passport

Laravel Passport provides OAuth2 server support to Laravel.

3.4k85.0M532](/packages/laravel-passport)[nolimits4web/swiper

Most modern mobile touch slider and framework with hardware accelerated transitions

41.8k177.2k1](/packages/nolimits4web-swiper)[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k36.7M259](/packages/laravel-dusk)[laravel/prompts

Add beautiful and user-friendly forms to your command-line applications.

712181.8M596](/packages/laravel-prompts)[cakephp/chronos

A simple API extension for DateTime.

1.4k47.7M121](/packages/cakephp-chronos)[laravel/pail

Easily delve into your Laravel application's log files directly from the command line.

91545.3M590](/packages/laravel-pail)

PHPackages © 2026

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