mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 15:12:48 +08:00
Think\Route的add方法更名为register方法 并支持批量注册功能(仅限于单个请求类型)
同时 get post put delete 和any 方法均支持 批量注册功能
This commit is contained in:
@@ -13,11 +13,11 @@ namespace Think;
|
|||||||
class Route {
|
class Route {
|
||||||
// 路由规则
|
// 路由规则
|
||||||
static private $rules = [
|
static private $rules = [
|
||||||
'get' => [],
|
'GET' => [],
|
||||||
'post' => [],
|
'POST' => [],
|
||||||
'put' => [],
|
'PUT' => [],
|
||||||
'delete' => [],
|
'DELETE' => [],
|
||||||
'all' => [],
|
'*' => [],
|
||||||
];
|
];
|
||||||
|
|
||||||
// 映射规则
|
// 映射规则
|
||||||
@@ -32,45 +32,47 @@ class Route {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加某个路由规则
|
// 注册某个路由规则
|
||||||
static public function add($rule,$route,$type='get'){
|
static public function register($rule,$route='',$type='GET'){
|
||||||
if(is_array($type)) {
|
if(is_array($type)) {
|
||||||
foreach ($type as $val){
|
foreach ($type as $val){
|
||||||
self::$rules[$val][$rule] = $route;
|
self::$rules[$val][$rule] = $route;
|
||||||
}
|
}
|
||||||
|
}elseif(is_array($rule)) {
|
||||||
|
self::$rules[$type] = array_merge(self::$rules[$type],$rule);
|
||||||
}else{
|
}else{
|
||||||
self::$rules[$type][$rule] = $route;
|
self::$rules[$type][$rule] = $route;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 导入路由规则
|
// 导入路由规则
|
||||||
static public function import($rules,$type='get'){
|
static public function import($rules,$type='GET'){
|
||||||
self::$rules[$type] = array_merge(self::$rules[$type],$rules);
|
self::$rules[$type] = array_merge(self::$rules[$type],$rules);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加一条任意请求的路由规则
|
// 添加一条任意请求的路由规则
|
||||||
static public function any($rule,$route){
|
static public function any($rule,$route=''){
|
||||||
self::add($rule,$route,'all');
|
self::register($rule,$route,'*');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加一条get请求的路由规则
|
// 添加一条get请求的路由规则
|
||||||
static public function get($rule,$route){
|
static public function get($rule,$route=''){
|
||||||
self::add($rule,$route,'get');
|
self::register($rule,$route,'GET');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加一条post请求的路由规则
|
// 添加一条post请求的路由规则
|
||||||
static public function post($rule,$route){
|
static public function post($rule,$route=''){
|
||||||
self::add($rule,$route,'post');
|
self::register($rule,$route,'POST');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加一条put请求的路由规则
|
// 添加一条put请求的路由规则
|
||||||
static public function put($rule,$route){
|
static public function put($rule,$route=''){
|
||||||
self::add($rule,$route,'put');
|
self::register($rule,$route,'PUT');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加一条delete请求的路由规则
|
// 添加一条delete请求的路由规则
|
||||||
static public function delete($rule,$route){
|
static public function delete($rule,$route=''){
|
||||||
self::add($rule,$route,'delete');
|
self::register($rule,$route,'DELETE');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检测URL路由
|
// 检测URL路由
|
||||||
@@ -83,9 +85,9 @@ class Route {
|
|||||||
return self::parseUrl(self::$map[$regx]);
|
return self::parseUrl(self::$map[$regx]);
|
||||||
}
|
}
|
||||||
// 路由规则检测
|
// 路由规则检测
|
||||||
$rules = self::$rules[strtolower($_SERVER['REQUEST_METHOD'])];
|
$rules = self::$rules[$_SERVER['REQUEST_METHOD']];
|
||||||
if(!empty(self::$rules['all'])) {
|
if(!empty(self::$rules['*'])) {
|
||||||
$rules = array_merge(self::$rules['all'],$rules);
|
$rules = array_merge(self::$rules['*'],$rules);
|
||||||
}
|
}
|
||||||
if(!empty($rules)) {
|
if(!empty($rules)) {
|
||||||
foreach ($rules as $rule=>$route){
|
foreach ($rules as $rule=>$route){
|
||||||
|
|||||||
Reference in New Issue
Block a user