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

ActiveLibrary

shiwolang/router
================

06PHP

Since Mar 3Pushed 10y ago1 watchersCompare

[ Source](https://github.com/shiwolang/router)[ Packagist](https://packagist.org/packages/shiwolang/router)[ RSS](/packages/shiwolang-router/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

RapidRouter 轻量级路由组件
===================

[](#rapidrouter-轻量级路由组件)

- 正则路由
- 非侵入式
- 以业务为中心进行嵌套和上下文包装
- 单纯的路由分发不和HTTP等耦合

\##使用方式

\###通过composer安装

```
$ composer require shiwolang/route

```

\###初始化路由容器 #####单个路由情景

```
Router::init();
```

\#####多个路由情景

```
Router::init("route");
Router::init("route1");
```

\###获取路由容器

```
$router  = Router::instance();
$router0 = Router::instance("route");
$router1 = Router::instance("route1");
```

\###添加路由

```
$router->addRoute(Route::init([
    "pattern"  => "#^php$#",
    "callback" => function () {
        return "nihao123";
     },
     "abstract" => true
]), "app.php");
$router->addRoute(Route::init([
    "pattern"  => "#^php/id/([a-z])+#",
    "callback" => HelloController::class . "::" . "nihao",
]), "app.php.a");
```

\###添加路由处理器

```
$router->addHandler(CallBack::init([
    "callback" => function (CallBack $result) {
        $result->invoke();
        echo "55\n";
    }
]), "app.php");
$router->addHandler(CallBack::init([
    "callback" => function (CallBack $result = null) {
        $result->invoke();
        echo "66\n";
    }
]), "app");
$router->addContext(CallBack::init([
    "callback" => function () {
        echo "11\n";
    },
    "handled"  => function () {
        echo "33\n";
    }
]), "app.php.a");
```

\###路由执行

```
Router::instance()->execute("php/id/aff");
Router::instance("route")->execute("php/id/aff");
```

\###组件使用思路 以业务作为中心，进行路由分发执行，并以路由为中心，进行嵌套和上下文的包装。 自由使用方式，轻松解决，分模块，分组等纠结的问题，一切以业务作为中心进行非侵入式的封装。

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/1bf0f9fca21d6e0b75646cd8febe1cf5caf1ed800392407d3aab3b2cf47d148a?d=identicon)[shiwolang](/maintainers/shiwolang)

---

Top Contributors

[![shiwolang](https://avatars.githubusercontent.com/u/5253315?v=4)](https://github.com/shiwolang "shiwolang (10 commits)")

### Embed Badge

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

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

PHPackages © 2026

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