PHPackages                             emerge/php-routing - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. emerge/php-routing

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

emerge/php-routing
==================

Emerge PHP Routing

0.1.2(7y ago)1298MITPHPCI failing

Since Nov 29Pushed 5y ago1 watchersCompare

[ Source](https://github.com/cx-emerge/php-routing)[ Packagist](https://packagist.org/packages/emerge/php-routing)[ RSS](/packages/emerge-php-routing/feed)WikiDiscussions main Synced 3w ago

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

简介
==

[](#简介)

一个基础的PHP路由

安装
==

[](#安装)

```
composer require emerge/php-routing

```

快速入门
====

[](#快速入门)

```
use Emerge\Routing;

$routing = new Routing();

$routing->get(
    '/admin',
    ['App\Admin', 'index']
);

$routing->get(
    '/admin/user/$id',
    ['App\Admin', 'index'],
    [
        'requirements' => [
            'id' => '\d+'
        ]
    ]
);

$result = $routing->dispatch('GET', '/admin/user/1');

print_r($result);
```

`输出内容`

```
Array
(
    [route] => /admin/user/$id

    [callback] => Array
    (
        [0] => App\Admin
        [1] => index
    )

    [options] => Array
    (
        [requirements] => Array
        (
            [id] => \d+
        )

        [method] => Array
        (
            [0] => GET
        )
    )

    [parameters] => Array
    (
        [0] => /admin/user/1
        [id] => 1
        [1] => 1
    )
)

```

常量
==

[](#常量)

`VERSION`
---------

[](#version)

>

**string**
*版本号*

```
$routing::VERSION
```

API
===

[](#api)

`get` - *路由设置*
--------------

[](#get---路由设置)

>

*array* `get` (*string* **$route**, *array|callable* **$callback**, \[*array* **$options = \[\]**\])
*返回添加的路由数据*

### 参数

[](#参数)

> `route`
>
> > 路由路径

> `callback`
>
> > 路由回调,[参考链接](http://php.net/manual/zh/language.types.callable.php)

> `options`
>
> > 路由选项, 支持 **requirements**,**method** 两个选项

### 返回值

[](#返回值)

```
Array
(
    [route] => /admin/user/$id

    [callback] => Array
    (
        [0] => App\Admin
        [1] => index
    )

    [options] => Array
    (
        [requirements] => Array
        (
            [id] => \d+
        )

        [method] => Array
        (
            [0] => GET
        )
    )
)

```

### 示例

[](#示例)

```
$routing->get(
    '/admin/user/$id',
    ['App\Admin', 'index'],
    [
        'method' => ['GET', 'POST']
        'requirements' => [
            'id' => '\d+'
        ]
    ]
);
```

`dispatch` - *分派路由*
-------------------

[](#dispatch---分派路由)

>

array `dispatch` (*string* **$method**, *string* **$uri**)
返回路由分派结果

### 参数

[](#参数-1)

> `method`
>
> > HTTP方法

> `uri`
>
> > URI

### 返回值

[](#返回值-1)

```
Array
(
    [route] => /admin/user/$id

    [callback] => Array
    (
        [0] => App\Admin
        [1] => index
    )

    [options] => Array
    (
        [requirements] => Array
        (
            [id] => \d+
        )

        [method] => Array
        (
            [0] => GET
        )
    )

    [parameters] => Array
    (
        [0] => /admin/user/1
        [id] => 1
        [1] => 1
    )
)

```

### 示例

[](#示例-1)

```
$result = $routing->dispatch('GET', '/admin/user/1');
```

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

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

Total

3

Last Release

2756d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a5f55d01d765e6c29007394c0c2d54b60b2b526d1160e1f2a8e37b8cac357db2?d=identicon)[emerge](/maintainers/emerge)

---

Top Contributors

[![cx-emerge](https://avatars.githubusercontent.com/u/3308685?v=4)](https://github.com/cx-emerge "cx-emerge (12 commits)")

---

Tags

phprouterouting

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/emerge-php-routing/health.svg)

```
[![Health](https://phpackages.com/badges/emerge-php-routing/health.svg)](https://phpackages.com/packages/emerge-php-routing)
```

PHPackages © 2026

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