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

ActiveLibrary[Framework](/categories/framework)

codesaur/router
===============

Хөнгөн, хурдан, объект-суурьтай маршрутчиллын (routing) компонент

v6.0.1(2d ago)11.1k↑194.1%1MITPHPPHP ^8.2.1CI passing

Since Mar 2Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/codesaur-php/Router)[ Packagist](https://packagist.org/packages/codesaur/router)[ Docs](https://github.com/codesaur-php)[ RSS](/packages/codesaur-router/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (5)Versions (44)Used By (1)

codesaur/router
===============

[](#codesaurrouter)

[![CI](https://github.com/codesaur-php/Router/actions/workflows/ci.yml/badge.svg)](https://github.com/codesaur-php/Router/actions/workflows/ci.yml)[![PHP Version](https://camo.githubusercontent.com/1015683ef28e870620edc19b6e22b456c0dc170c260fa4645905e93438f607a6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e322e312d3737374242342e7376673f6c6f676f3d706870)](https://www.php.net/)[![License](https://camo.githubusercontent.com/784362b26e4b3546254f1893e778ba64616e362bd6ac791991d2c9e880a3a64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e737667)](https://camo.githubusercontent.com/784362b26e4b3546254f1893e778ba64616e362bd6ac791991d2c9e880a3a64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e737667)

Агуулга / Table of Contents
---------------------------

[](#агуулга--table-of-contents)

1. [Монгол](#1-%D0%BC%D0%BE%D0%BD%D0%B3%D0%BE%D0%BB-%D1%82%D0%B0%D0%B9%D0%BB%D0%B1%D0%B0%D1%80) | 2. [English](#2-english-description) | 3. [Getting Started](#3-getting-started)

---

1. Монгол тайлбар
-----------------

[](#1-монгол-тайлбар)

Хөнгөн, хурдан, объект-суурьтай маршрутчиллын (routing) компонент. Динамик параметрүүд, нэртэй маршрутууд, reverse routing зэрэг бүх шаардлагатай боломжуудыг дэмждэг.

`codesaur/router` нь **codesaur ecosystem**-ийн нэг хэсэг бөгөөд хөнгөн жинтэй, фрэймворкоос үл хамааран standalone байдлаар ашиглаж болох PHP routing компонент юм.

Багц нь дараах 3 үндсэн class-аас бүрдэнэ:

- **Router** - маршрут бүртгэх, тааруулах, URL үүсгэх үндсэн класс
- **RouterInterface** - router-ийн бүрэн contract (`match`, `generate`, `pattern`, `getRoutes`). 3rd-party router-уудыг adapter-аар ороож ашиглах боломж олгоно.
- **Route** - immutable value object - `Router::__call()`-ийн буцаах утга. `->name(...)`, `->middleware([...])` гэх мэт fluent API-д ашиглагдана.

### Дэлгэрэнгүй мэдээлэл

[](#дэлгэрэнгүй-мэдээлэл)

- [Бүрэн танилцуулга](docs/mn/README.md) - Суурилуулалт, хэрэглээ, жишээнүүд
- [API тайлбар](docs/mn/api.md) - Бүх метод, exception-үүдийн тайлбар
- [Шалгалтын тайлан](docs/mn/review.md) - Код шалгалтын тайлан

---

2. English description
----------------------

[](#2-english-description)

A lightweight, fast, object-oriented routing component. Supports dynamic parameters, named routes, reverse routing, and all essential routing features.

`codesaur/router` is part of the **codesaur ecosystem** and is a lightweight PHP routing component that can be used standalone, independent of any framework.

The package consists of the following 3 core classes:

- **Router** - main class for registering routes, matching requests, and generating URLs
- **RouterInterface** - full router contract (`match`, `generate`, `pattern`, `getRoutes`). Allows third-party routers to be adapted and used in `codesaur/http-application`.
- **Route** - immutable value object returned by `Router::__call()`. Provides fluent API such as `->name(...)`, `->middleware([...])`.

### Documentation

[](#documentation)

- [Full Documentation](docs/en/README.md) - Installation, usage, examples
- [API Reference](docs/en/api.md) - Complete API documentation
- [Review](docs/en/review.md) - Code review report

---

3. Getting Started
------------------

[](#3-getting-started)

### Requirements

[](#requirements)

- PHP **8.2.1+**
- Composer

### Installation

[](#installation)

Composer ашиглан суулгана / Install via Composer:

```
composer require codesaur/router
```

### Quick Example

[](#quick-example)

```
use codesaur\Router\Router;

$router = new Router();

// Энгийн GET маршрут / Simple GET route
$router->GET('/hello', function() {
    echo 'Hello, World!';
});

// Динамик параметртэй маршрут / Route with dynamic parameters
$router->GET('/news/{int:id}', function(int $id) {
    echo "News ID: $id";
})->name('news-view');

// UTF-8 параметр / UTF-8 parameter (Cyrillic, CJK, etc.)
$router->GET('/search/{utf8:query}', function(string $query) {
    echo "Search: $query";
})->name('search');

// Per-route middleware - (pattern, method) scope-той / scoped to the (pattern, method) pair
$router->POST('/api/users', [UserController::class, 'create'])
    ->middleware([CsrfMiddleware::class, AuthMiddleware::class])
    ->name('users.create');

// Append semantics - олон ->middleware() chain цуглуулагдана / chained calls accumulate
$router->GET('/admin', [AdminController::class, 'dashboard'])
    ->middleware([AuthMiddleware::class])
    ->middleware([AdminOnlyMiddleware::class]);

// Маршрут тааруулах / Match route
// match() буцаах: [callable, params, middleware] тогтмол 3-tuple эсвэл null
$result = $router->match('/news/10', 'GET');
if ($result !== null) {
    [$callable, $params, $middleware] = $result;
    \call_user_func_array($callable, $params);
}

// URL үүсгэх / Generate URL
$url = $router->generate('news-view', ['id' => 10]); // -> /news/10

// Client-side substitution-д бэлэн pattern / Pattern for client-side substitution
$pattern = $router->pattern('news-view'); // -> /news/{id}
```

### Running Tests

[](#running-tests)

Тест ажиллуулах / Run tests:

```
# Бүх тестүүдийг ажиллуулах / Run all tests
composer test

# Coverage-тэй тест ажиллуулах / Run tests with coverage
composer test:coverage
```

---

Changelog
---------

[](#changelog)

- [CHANGELOG.md](CHANGELOG.md) - Full version history

Contributing &amp; Security
---------------------------

[](#contributing--security)

- [Contributing Guide](.github/CONTRIBUTING.md)
- [Security Policy](.github/SECURITY.md)

License
-------

[](#license)

This project is licensed under the MIT License.

Author
------

[](#author)

**Narankhuu**

**codesaur ecosystem:**

###  Health Score

56

—

FairBetter than 97% of packages

Maintenance95

Actively maintained with recent releases

Popularity22

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity78

Established project with proven stability

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

Recently: every ~30 days

Total

43

Last Release

2d ago

Major Versions

v1.2.1 → v2.02021-09-18

v2.2 → v3.02021-09-23

v3.4 → v4.02021-10-06

v4.6.0 → v5.0.02026-01-08

v5.2.0 → v6.0.02026-05-24

PHP version history (3 changes)v1.0PHP &gt;=7.2.0

v4.2.0PHP &gt;=8.2.1

v5.0.0PHP ^8.2.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4127594?v=4)[Наранхүү Н](/maintainers/codesaur)[@codesaur](https://github.com/codesaur)

---

Top Contributors

[![codesaur](https://avatars.githubusercontent.com/u/4127594?v=4)](https://github.com/codesaur "codesaur (62 commits)")

---

Tags

routerroutecodesaurmongolmongolianarankhuucodenкодзаврнаранхүүкоден

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[pecee/simple-router

Simple, fast PHP router that is easy to get integrated and in almost any project. Heavily inspired by the Laravel router.

675231.0k18](/packages/pecee-simple-router)[izniburak/router

simple router class for php

23423.5k7](/packages/izniburak-router)[ecoal95/php-router

Minimal routing library

271.0k1](/packages/ecoal95-php-router)[rosengate/exedra

Nestful route oriented PHP micro framework

152.0k1](/packages/rosengate-exedra)[developermarius/simple-router

Simple, fast PHP router that is easy to get integrated and in almost any project. Heavily inspired by the Laravel router.

112.5k](/packages/developermarius-simple-router)

PHPackages © 2026

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