mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-08 23:52:49 +08:00
Route类express方法更名为alias 增加methodPrefix属性 用于设置不同请求类型的操作方法前缀
This commit is contained in:
@@ -35,6 +35,14 @@ class Route
|
|||||||
'delete' => ['DELETE', '/:id', 'delete'],
|
'delete' => ['DELETE', '/:id', 'delete'],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// 不同请求类型的方法前缀
|
||||||
|
private static $methodPrefix = [
|
||||||
|
'GET' => '',
|
||||||
|
'POST' => '',
|
||||||
|
'PUT' => '',
|
||||||
|
'DELETE' => '',
|
||||||
|
];
|
||||||
|
|
||||||
// URL映射规则
|
// URL映射规则
|
||||||
private static $map = [];
|
private static $map = [];
|
||||||
// 子域名部署规则
|
// 子域名部署规则
|
||||||
@@ -216,12 +224,19 @@ class Route
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 注册快捷路由
|
// 注册别名路由
|
||||||
public static function express($rule, $route = '', $option = [], $pattern = [])
|
public static function alias($rule, $route = '', $option = [], $pattern = [])
|
||||||
{
|
{
|
||||||
$method = ['get', 'post', 'put', 'delete'];
|
self::any($rule . '/:action', $route . '/:action', $option, $pattern);
|
||||||
foreach ($method as $type) {
|
}
|
||||||
self::$type($rule . '/:action', $route . '/' . $type . ':action', $option, $pattern);
|
|
||||||
|
// 设置不同请求类型下面的方法前缀
|
||||||
|
public static function setMethodPrefix($method, $prefix = '')
|
||||||
|
{
|
||||||
|
if (is_array($method)) {
|
||||||
|
self::$methodPrefix = array_merge(self::$methodPrefix, array_change_key_case($method, CASE_UPPER));
|
||||||
|
} else {
|
||||||
|
self::$methodPrefix[strtoupper($method)] = $prefix;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -593,6 +608,8 @@ class Route
|
|||||||
// REST 操作方法支持
|
// REST 操作方法支持
|
||||||
if ('[rest]' == $action) {
|
if ('[rest]' == $action) {
|
||||||
$action = REQUEST_METHOD;
|
$action = REQUEST_METHOD;
|
||||||
|
} elseif (isset(self::$methodPrefix[REQUEST_METHOD])) {
|
||||||
|
$action = self::$methodPrefix[REQUEST_METHOD] . $action;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$route = [$module, $controller, $action];
|
$route = [$module, $controller, $action];
|
||||||
|
|||||||
Reference in New Issue
Block a user