2017 © Pedro Peláez
 

library tast-router

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

image

xujiajun/tast-router

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

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 6 Forks
  • 0 Open issues
  • 4 Versions
  • 2 % Grown

The README.md

TastRouter License Code Climate Build Status

A Simple PHP Router, (*1)

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

Requirements

PHP5.4+, (*2)

composer方式获得

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

当然也可以直接clone, (*3)

Usage

step1, (*4)

sudo composer install

step2:, (*5)


//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

以上用法太麻烦?, (*6)

TastRouter也支持Yaml的配置.方便管理你的路由:, (*7)

//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

MIT Licensed, (*8)

The Versions

15/07 2017

dev-master

9999999-dev https://github.com/xujiajun/tast-router

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

  Sources   Download

MIT

The Requires

 

The Development Requires

php rest router tast

27/09 2016

2.0.x-dev

2.0.9999999.9999999-dev https://github.com/xujiajun/tast-router

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

  Sources   Download

MIT

The Requires

 

The Development Requires

php rest router tast

23/07 2015

1.0.x-dev

1.0.9999999.9999999-dev https://github.com/xujiajun/TastRouter

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

  Sources   Download

MIT

The Requires

 

The Development Requires

php rest router tast

23/07 2015

v1.0

1.0.0.0 https://github.com/xujiajun/TastRouter

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

  Sources   Download

MIT

The Requires

 

The Development Requires

php rest router tast