/** * @brief dispatch 路由分发方法 * * @return void */ public static function dispatch() { // 注册最后的通用路由 $route = array('widget' => 'Page', 'method' => 'showPage', 'format' => '/%s/', 'patter' => '|^/([^/]+)[/]?$|', 'params' => array('alias')); self::setRoute('Page', $route); // 获取地址信息 if (OptionLibrary::get('rewrite') == 'open') { $pathInfo = str_replace(substr(LOGX_PATH, 0, strlen(LOGX_PATH) - 1), '', Request::S('REQUEST_URI', 'string')); $pathInfo = str_replace('?' . Request::S('QUERY_STRING', 'string'), '', $pathInfo); } else { $pathInfo = self::getPathInfo(); } $pathInfo = Plugin::call('pathInfo', $pathInfo); // 遍历路由表进行匹配 foreach (self::$_routeTable as $key => $route) { if (preg_match($route['patter'], $pathInfo, $matches)) { self::$_currentRoute = $key; $params = NULL; if (!empty($route['params'])) { unset($matches[0]); $params = array_combine($route['params'], $matches); } self::$_currentParams = $params; if (isset($route['widget'])) { Widget::getWidget($route['widget'])->{$route}['method']($params); } elseif (isset($route['plugin'])) { Plugin::getPlugin($route['plugin'])->{$route}['method']($params); } return; } } //echo '**'.$_SERVER['QUERY_STRING']; //$path = explode( '/', $pathInfo ); // 永久重定向为规范的 URL 地址 //Response::redirect( $pathInfo.'/', true ); // 没有匹配的路由则显示 404 页面 Response::error(404); }