public function parseUrl()
{
$path = '/';
//定义URL常量
$subDir = dirname($_SERVER['SCRIPT_NAME']);
if ($subDir == '/' || $subDir == '\\') {
$subDir = '';
}
//定义项目根目录地址
self::$urlParams['root'] = $subDir . '/';
\Cml\Route::parsePathInfo();
$pathInfo = \Cml\Route::getPathInfo();
//检测路由
if (self::$rules) {
//配置了路由,所有请求通过路由处理
$isRoute = self::isRoute($pathInfo);
if ($isRoute[0]) {
//匹配路由成功
if (is_array($isRoute['route'])) {
self::$urlParams['action'] = $isRoute['route'][2];
self::$urlParams['controller'] = $isRoute['route'][1];
$path = self::$urlParams['path'] = $isRoute['route'][0];
} else {
$routeArr = explode('/', $isRoute['route']);
$isRoute = null;
self::$urlParams['action'] = array_pop($routeArr);
self::$urlParams['controller'] = ucfirst(array_pop($routeArr));
$controllerPath = '';
$routeAppHierarchy = Config::get('route_app_hierarchy', 1);
$i = 0;
while ($dir = array_shift($routeArr)) {
if ($i++ < $routeAppHierarchy) {
$path .= $dir . '/';
} else {
$controllerPath .= $dir . '/';
}
}
self::$urlParams['controller'] = $controllerPath . self::$urlParams['controller'];
unset($routeArr);
}
} else {
self::findAction($pathInfo, $path);
//未匹配到路由 按文件名映射查找
}
} else {
self::findAction($pathInfo, $path);
//未匹配到路由 按文件名映射查找
}
$pathInfo = array_values($pathInfo);
for ($i = 0; $i < count($pathInfo); $i += 2) {
$_GET[$pathInfo[$i]] = $pathInfo[$i + 1];
}
unset($pathInfo);
self::$urlParams['path'] = $path ? $path : '/';
unset($path);
$_REQUEST = array_merge($_REQUEST, $_GET);
}