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

ActiveLibrary[Framework](/categories/framework)

attribute-router/router
=======================

AttributeRouter is a lightweight and intuitive routing solution for PHP applications

v1.2.0(9mo ago)031PHP

Since Nov 6Pushed 9mo ago1 watchersCompare

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

READMEChangelog (1)Dependencies (2)Versions (4)Used By (0)

```
composer require attribute-router/router
```

Controller
==========

[](#controller)

```
declare(strict_types=1);

namespace Controller;

use AttributeRouter\Route;
use AttributeRouter\RouteGroup;

#[RouteGroup(path: '/admin', priority: 5)]
class HomeController
{
    #[Route(
        path: '/edit/{id}/{uuid?}',
        methods: ['GET'],
        name: 'edit',
        patterns: ['id' => '[0-9]+'],
        priority: 10
    )]
    public function edit(int $id, ?string $uuid = null)
    {
        //
    }
}
```

Initialization
==============

[](#initialization)

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

use Controller\HomeController;
use AttributeRouter\Router;
use DI\Container;
use Controller\TestController;

$container = new Container;
$router = $container->get(Router::class);
$router->registerRoutes([
    HomeController::class,
    TestController::class,
]);

$requestUri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$requestMethod = $_SERVER['REQUEST_METHOD'];
$router->dispatch($requestUri, $requestMethod);
$router->invokeController();
```

It is also possible to specify languages. But it should be specified before registering the controllers. In this case, the parameter /{locale?}/ will be automatically added to the beginning of all routes. A question mark means that this is an optional parameter. For example in the route /blog/123, would mean the default language, route /fr/blog/123, the French version.

```
$container = new Container;
$router = $container->get(Router::class);
$router->setDefaultLocale('en')->setLocales(['en', 'ru', 'fr']);
$router->registerRoutes([
    HomeController::class,
    TestController::class,
]);

$requestUri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$requestMethod = $_SERVER['REQUEST_METHOD'];
$router->dispatch($requestUri, $requestMethod);
$router->invokeController();
```

Cached routes can be forwarded. This method is shown for familiarization. You can use special classes for this.

```
$container = new Container;
$router = $container->get(Router::class);
$router->registerRoutes([
    HomeController::class,
    TestController::class,
]);

file_put_contents('cache.txt', serialize($router->getRoutes()));
```

If routes are cached, you can do without registering controllers

```
$container = new Container;
$router = $container->get(Router::class);

$data = unserialize(file_get_contents('cache.txt'));

$router->setRoutes($data);
$router->dispatch($requestUri, $requestMethod);
$router->invokeController();
```

Current route

```
var_dump($router->getCurrent());
```

All routes

```
var_dump($router->getRoutes());
```

Register a new named parameter

```
$router->setAlias(alias: 'username', pattern: '[a-zA-Z0-9-_]+');
```

Get all named parameter

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

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance57

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

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

Total

3

Last Release

288d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9284f8acd39c92ae0e4e2abbf5893e1516e1315766c3fac23007e1f24ec2d6fd?d=identicon)[programmerer1](/maintainers/programmerer1)

---

Top Contributors

[![programmerer1](https://avatars.githubusercontent.com/u/127964624?v=4)](https://github.com/programmerer1 "programmerer1 (42 commits)")

---

Tags

phpphp-attributesphp-routerrouterrouting

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[slim/slim-skeleton

A Slim Framework skeleton application for rapid development

1.6k458.7k6](/packages/slim-slim-skeleton)[elgg/elgg

Elgg is an award-winning social networking engine, delivering the building blocks that enable businesses, schools, universities and associations to create their own fully-featured social networks and applications.

1.7k15.7k5](/packages/elgg-elgg)[php-di/slim-bridge

PHP-DI integration in Slim

1786.7M98](/packages/php-di-slim-bridge)[php-di/silex-bridge

PHP-DI integration in Silex

2465.4k1](/packages/php-di-silex-bridge)[forme/framework

An MVC framework for WordPress.

175.0k3](/packages/forme-framework)

PHPackages © 2026

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