mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
废除模块映射功能 改进route助手函数 Route类增加rule方法替代原register方法,原register方法更名为import方法用于导入路由配置
This commit is contained in:
@@ -358,7 +358,7 @@ function view($template = '', $vars = [])
|
||||
*/
|
||||
function route($rule = '', $route = [], $type = '*', $option = [], $pattern = [])
|
||||
{
|
||||
Route::register($rule, $route, $type, $option, $pattern);
|
||||
Route::rule($rule, $route, $type, $option, $pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -191,17 +191,6 @@ class App
|
||||
if (APP_MULTI_MODULE) {
|
||||
// 多模块部署
|
||||
$module = strtolower($result[0] ?: $config['default_module']);
|
||||
if ($maps = $config['url_module_map']) {
|
||||
if (isset($maps[$module])) {
|
||||
// 记录当前别名
|
||||
define('MODULE_ALIAS', $module);
|
||||
// 获取实际的项目名
|
||||
$module = $maps[MODULE_ALIAS];
|
||||
} elseif (array_search($module, $maps)) {
|
||||
// 禁止访问原始项目
|
||||
$module = '';
|
||||
}
|
||||
}
|
||||
// 获取模块名称
|
||||
define('MODULE_NAME', strip_tags($module));
|
||||
|
||||
@@ -335,8 +324,8 @@ class App
|
||||
if (APP_ROUTE_ON && !empty($config['url_route_on'])) {
|
||||
// 开启路由
|
||||
if (!empty($config['route'])) {
|
||||
// 注册路由定义文件
|
||||
Route::register($config['route']);
|
||||
// 导入路由配置
|
||||
Route::import($config['route']);
|
||||
}
|
||||
// 路由检测(根据路由定义返回不同的URL调度)
|
||||
$result = Route::check($request, $_SERVER['PATH_INFO'], $depr, !IS_CLI ? $config['url_domain_deploy'] : false);
|
||||
|
||||
@@ -97,63 +97,46 @@ class Route
|
||||
}
|
||||
}
|
||||
|
||||
// 注册路由规则
|
||||
public static function register($rule, $route = '', $type = '*', $option = [], $pattern = [])
|
||||
// 导入配置文件定义的路由规则
|
||||
public static function import(array $rule, $type = '*')
|
||||
{
|
||||
if (strpos($type, '|')) {
|
||||
foreach (explode('|', $type) as $val) {
|
||||
self::register($rule, $route, $val, $option);
|
||||
}
|
||||
} else {
|
||||
if (is_array($rule)) {
|
||||
// 检查域名部署
|
||||
if (isset($rule['__domain__'])) {
|
||||
self::domain($rule['__domain__']);
|
||||
unset($rule['__domain__']);
|
||||
}
|
||||
// 检查变量规则
|
||||
if (isset($rule['__pattern__'])) {
|
||||
self::pattern($rule['__pattern__']);
|
||||
unset($rule['__pattern__']);
|
||||
}
|
||||
// 检查路由映射
|
||||
if (isset($rule['__map__'])) {
|
||||
self::map($rule['__map__']);
|
||||
unset($rule['__map__']);
|
||||
}
|
||||
// 检查资源路由
|
||||
if (isset($rule['__rest__'])) {
|
||||
self::resource($rule['__rest__']);
|
||||
unset($rule['__rest__']);
|
||||
}
|
||||
// 检查域名部署
|
||||
if (isset($rule['__domain__'])) {
|
||||
self::domain($rule['__domain__']);
|
||||
unset($rule['__domain__']);
|
||||
}
|
||||
// 检查变量规则
|
||||
if (isset($rule['__pattern__'])) {
|
||||
self::pattern($rule['__pattern__']);
|
||||
unset($rule['__pattern__']);
|
||||
}
|
||||
// 检查路由映射
|
||||
if (isset($rule['__map__'])) {
|
||||
self::map($rule['__map__']);
|
||||
unset($rule['__map__']);
|
||||
}
|
||||
// 检查资源路由
|
||||
if (isset($rule['__rest__'])) {
|
||||
self::resource($rule['__rest__']);
|
||||
unset($rule['__rest__']);
|
||||
}
|
||||
|
||||
foreach ($rule as $key => $val) {
|
||||
if (is_numeric($key)) {
|
||||
$key = array_shift($val);
|
||||
}
|
||||
if (0 === strpos($key, '[')) {
|
||||
if (empty($val)) {
|
||||
continue;
|
||||
}
|
||||
$key = substr($key, 1, -1);
|
||||
$result = ['routes' => $val, 'option' => $option, 'pattern' => $pattern];
|
||||
} elseif (is_array($val)) {
|
||||
$result = ['route' => $val[0], 'option' => $val[1], 'pattern' => isset($val[2]) ? $val[2] : []];
|
||||
} else {
|
||||
$result = ['route' => $val, 'option' => $option, 'pattern' => $pattern];
|
||||
}
|
||||
self::$rules[$type][$key] = $result;
|
||||
foreach ($rule as $key => $val) {
|
||||
if (is_numeric($key)) {
|
||||
$key = array_shift($val);
|
||||
}
|
||||
if (0 === strpos($key, '[')) {
|
||||
if (empty($val)) {
|
||||
continue;
|
||||
}
|
||||
$key = substr($key, 1, -1);
|
||||
$result = ['routes' => $val, 'option' => [], 'pattern' => []];
|
||||
} elseif (is_array($val)) {
|
||||
$result = ['route' => $val[0], 'option' => $val[1], 'pattern' => isset($val[2]) ? $val[2] : []];
|
||||
} else {
|
||||
if (0 === strpos($rule, '[')) {
|
||||
$rule = substr($rule, 1, -1);
|
||||
$result = ['routes' => $route, 'option' => $option, 'pattern' => $pattern];
|
||||
} else {
|
||||
$result = ['route' => $route, 'option' => $option, 'pattern' => $pattern];
|
||||
}
|
||||
self::$rules[$type][$rule] = $result;
|
||||
$result = ['route' => $val, 'option' => [], 'pattern' => []];
|
||||
}
|
||||
|
||||
self::$rules[$type][$key] = $result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,6 @@ class routeTest extends \PHPUnit_Framework_TestCase
|
||||
Route::any('user/:id', 'index/user');
|
||||
$this->assertEquals(['type' => 'module', 'module' => [null, 'index', 'hello']], Route::check($request, 'hello/thinkphp'));
|
||||
$this->assertEquals(['hello/:name' => ['route' => 'index/hello', 'option' => [], 'pattern' => []]], Route::getRules('GET'));
|
||||
Route::register('type/:name', 'index/type', 'PUT|POST');
|
||||
Route::rule('type/:name', 'index/type', 'PUT|POST');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user