PHPackages                             xujiajun/tast-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. [HTTP &amp; Networking](/categories/http)
4. /
5. xujiajun/tast-router

ActiveLibrary[HTTP &amp; Networking](/categories/http)

xujiajun/tast-router
====================

A Simple PHP Router.support REST and reverse routing etc.

v1.0(10y ago)111426MITPHPPHP &gt;=5.4.0

Since Jul 23Pushed 8y agoCompare

[ Source](https://github.com/xujiajun/tast-router)[ Packagist](https://packagist.org/packages/xujiajun/tast-router)[ Docs](https://github.com/xujiajun/TastRouter)[ RSS](/packages/xujiajun-tast-router/feed)WikiDiscussions master Synced 1mo ago

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

TastRouter [![License](https://camo.githubusercontent.com/81649c9de2bbb95b6f577824e61bb0c92045d423cde2bfbf17efb323accf3912/68747470733a2f2f706f7365722e707567782e6f72672f78756a69616a756e2f746173742d726f757465722f6c6963656e7365)](https://packagist.org/packages/xujiajun/tast-router) [![Code Climate](https://camo.githubusercontent.com/9a45ac6df77b6e36afa2e1026f06ce6f1406df87380721d456dd6b714e4bb33b/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f78756a69616a756e2f746173742d726f757465722f6261646765732f6770612e737667)](https://codeclimate.com/github/xujiajun/tast-router) [![Build Status](https://camo.githubusercontent.com/8b5779855e4349aa3a40f0da2b8458b59a9576ca045dee33c0f32b64d2b8800e/68747470733a2f2f7472617669732d63692e6f72672f78756a69616a756e2f746173742d726f757465722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/xujiajun/tast-router)
=====================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#tastrouter----)

A Simple PHP Router

- 支持RESTful风格
- 支持反向路由
- 支持动态参数绑定
- 支持对参数正则检验
- 支持Yaml格式的路由配置

Requirements
------------

[](#requirements)

PHP5.4+

composer方式获得
------------

[](#composer方式获得)

```
{
    "require":{
        "xujiajun/tast-router":"dev-master"
    }
}

```

当然也可以直接clone

Usage
-----

[](#usage)

step1

```
sudo composer install

```

step2:

```

//web/index.php

require __DIR__.'/../vendor/autoload.php';
use TastRouter\Route;
use TastRouter\Router;
use TastRouter\RouteCollection;

$collection = new RouteCollection();

$controller = 'TastRouter\\App\\Controllers\\UserController';

//普通用法
$collection
->attachRoute(new Route('/user/do',[
    '_controller' => "$controller::doAction",
    'methods' => 'GET',
]));

//使用正则
$collection
->attachRoute(new Route('/user/{user}',[
    '_controller' => "$controller::indexAction",
    'methods' => 'GET',
    'user'=>'\w+',
//    'id'=>'\d+',
]));

//路由名绑定
$collection
->attachRoute(new Route('/hello/{hello}',[
    '_controller' => "$controller::indexAction",
    'methods' => 'GET',
    'hello'=>'\w+',
    'routeName'=>'say_hello',//bind route name
//    'id'=>'\d+',
]));

$router = new Router($collection);
$route = $router->matchCurrentRequest();

//解析路由
echo $router->generate('say_hello',['hello'=>'xujiajun']);// 输出 /hello/xujiajun

```

以上用法太麻烦？

TastRouter也支持Yaml的配置.方便管理你的路由:

```
//web/index.php

require __DIR__.'/../vendor/autoload.php';
use TastRouter\Router;
use Symfony\Component\Yaml\Yaml;

$file = __DIR__.'/../src/Config/routes.yml';
$array = Yaml::parse(file_get_contents($file));
$router = Router::parseConfig($array);
$route = $router->matchCurrentRequest();

```

License
-------

[](#license)

[MIT Licensed](http://www.opensource.org/licenses/MIT)

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity60

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

Total

3

Last Release

3521d ago

Major Versions

v1.0 → 2.0.x-dev2016-09-27

### Community

Maintainers

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

---

Top Contributors

[![xujiajun](https://avatars.githubusercontent.com/u/6065007?v=4)](https://github.com/xujiajun "xujiajun (22 commits)")

---

Tags

phpphp-routertastphprestroutertast

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[aphiria/aphiria

The Aphiria framework

1427.7k2](/packages/aphiria-aphiria)[travisghansen/kubernetes-client-php

Kubernetes API client in PHP supporting REST operations and Watches

3726.0k3](/packages/travisghansen-kubernetes-client-php)[rizeway/orem

Rizeway OREM is a Restful API Abstraction Layer. It is to Restful APIs what doctrine is for databases.

266.1k](/packages/rizeway-orem)

PHPackages © 2026

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