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