mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-09 08:02:48 +08:00
增加资源路由嵌套支持
This commit is contained in:
@@ -21,9 +21,9 @@ class Route
|
||||
'DELETE' => [],
|
||||
'HEAD' => [],
|
||||
'*' => [],
|
||||
'REST' => [],
|
||||
];
|
||||
|
||||
// REST路由操作方法定义
|
||||
private static $rest = [
|
||||
'index' => ['GET', ''],
|
||||
'create' => ['GET', '/create'],
|
||||
@@ -33,6 +33,7 @@ class Route
|
||||
'update' => ['PUT', '/:id'],
|
||||
'delete' => ['DELETE', '/:id'],
|
||||
];
|
||||
|
||||
// URL映射规则
|
||||
private static $map = [];
|
||||
// 子域名部署规则
|
||||
@@ -187,18 +188,25 @@ class Route
|
||||
if (is_array($rule)) {
|
||||
foreach ($rule as $key => $val) {
|
||||
if (is_array($val)) {
|
||||
$val = array_pad($val, 3, []);
|
||||
self::resource($key, $val[0], $val[1], $val[2]);
|
||||
} else {
|
||||
self::resource($key, $val, $option, $pattern);
|
||||
list($val, $option, $pattern) = array_pad($val, 3, []);
|
||||
}
|
||||
self::resource($key, $val, $option, $pattern);
|
||||
}
|
||||
} else {
|
||||
if (strpos($rule, '.')) {
|
||||
// 注册嵌套资源路由
|
||||
list($rule1, $rule2) = explode('.', $rule);
|
||||
self::get($rule1 . '/:' . $rule1 . '_id/' . $rule2 . '/:' . $rule2 . '_id$', $route . '/read', $option, $pattern);
|
||||
$array = explode('.', $rule);
|
||||
$last = array_pop($array);
|
||||
$item = [];
|
||||
foreach ($array as $val) {
|
||||
if (isset($option['rule'][$val])) {
|
||||
$item[] = $val . '/:' . $option['rule'][$val];
|
||||
} else {
|
||||
$item[] = $val . '/:' . $val . '_id';
|
||||
}
|
||||
}
|
||||
$rule = implode('/', $item) . '/' . $last;
|
||||
}
|
||||
// 注册资源路由
|
||||
foreach (self::$rest as $key => $val) {
|
||||
if ((isset($option['only']) && !in_array($key, $option['only']))
|
||||
@@ -209,7 +217,6 @@ class Route
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// rest方法定义和修改
|
||||
public static function rest($method, $resocure = '')
|
||||
@@ -251,10 +258,9 @@ class Route
|
||||
}
|
||||
// 子域名配置
|
||||
if (!empty($domain)) {
|
||||
// 记录子域名
|
||||
self::$subDomain = join('.', $domain);
|
||||
// 二级域名
|
||||
// 当前子域名
|
||||
$subDomain = implode('.', $domain);
|
||||
self::$subDomain = $subDomain;
|
||||
$domain2 = array_pop($domain);
|
||||
if ($domain) {
|
||||
// 存在三级域名
|
||||
|
||||
Reference in New Issue
Block a user