PHPackages                             cutephp/route - 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. cutephp/route

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

cutephp/route
=============

a simple route

v1.0.1(11y ago)4215414[2 issues](https://github.com/NauxLiu/route/issues)mitPHP

Since Nov 6Pushed 9y ago4 watchersCompare

[ Source](https://github.com/NauxLiu/route)[ Packagist](https://packagist.org/packages/cutephp/route)[ RSS](/packages/cutephp-route/feed)WikiDiscussions master Synced today

READMEChangelog (2)DependenciesVersions (3)Used By (0)

\#安装 在你的composer.json中添加

```
"require": {
    "cutephp/route": "~1.0"
},
```

\#使用

\####添加基本路由 调用和HTTP方法同名的函数名来添加路由，第一个参数为接受的URI，第二个参数为任意类型。匹配成功后可通过`getStorage()`方法原样取出。

```
use CutePHP\Route\Router;

$router = new Router;
//添加一个接受Get请求的路由
$router->get('/test', 'test');
//添加一个接受Post请求的路由
$router->post('/test', 'test');
//添加一个接受Delete请求的路由
$router->delete('/test', 'test');
//添加一个接受Put请求的路由
$router->put('/test', 'test');
//添加一个接受Head请求的路由
$router->head('/test', 'test');
//添加一个接受Patch请求的路由
$router->patch('/test', 'test');
```

> 注意：GET路由会同意匹配HEAD请求。

\####获得匹配的路由

```
use CutePHP\Route\Router;

$router = new Router;

$router->get('/about', '这是/about路由');
$router->get('/articles', '这是/articles路由');

//第一个参数为URI，第二个参数为HTTP方法。返回匹配的Route对象
$route = $router->match('/about','get');

//取出添加时第二个参数存储的值
echo $route->getStorage();
```

会看到结果为`这是/about路由`的输出

\####添加同时支持多种HTTP方法的路由 通过调用`via`方法传入多个http方法名

```
$router->add('/test',function(){
    return 123;
})->via('get','post');
```

\####有名字的路由

```
$router->get('/test', 123, 'MyName');
$res = $route->name('MyName');

$res->getUri(); // '/test'
$res->getStorage(); // 123
$res->getMethods(); // array( 0 => 'GET')
```

\####添加可以接受参数的路由 路由参数节点使用`:`做前缀标识

```
$router->get('/test/:id',function(){
    return 123;
});

$res = $router->match('/test/2','get');
$params = $res->getParams();
var_dump($params);
```

输出结果为

```
array(1) {
  ["id"]=>
  string(1) "2"
}

```

\####添加可选参数的路由

```
$router->get('/users/:id?',function(){
    return 123;
});
```

这时`/users`或`/users/1`都可匹配到此路由。如果匹配`/users/1`,`getParams()`还可获得`id`对应`1`的数组。

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity64

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

Total

2

Last Release

4244d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/22071ff5935f95277f8b0c794c2f23703e6de307ed0e65e25e7c3a878a45c012?d=identicon)[NauxLiu](/maintainers/NauxLiu)

---

Top Contributors

[![nauxliu](https://avatars.githubusercontent.com/u/9570112?v=4)](https://github.com/nauxliu "nauxliu (5 commits)")

### Embed Badge

![Health badge](/badges/cutephp-route/health.svg)

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

###  Alternatives

[alexbowers/laravel-fake-cron

5528.3k](/packages/alexbowers-laravel-fake-cron)[denpa/laravel-zeromq

ZeroMQ driver for Laravel

171.2k](/packages/denpa-laravel-zeromq)

PHPackages © 2026

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