/** * 路由分发函数 * * @param string $path 目的文件所在目录 * @return void * @throws Typecho_Route_Exception */ public static function dispatch() { /** 获取PATHINFO */ $pathInfo = self::getPathInfo(); foreach (self::$_routingTable as $key => $route) { if (preg_match($route['regx'], $pathInfo, $matches)) { self::$current = $key; try { /** 载入参数 */ $params = NULL; if (!empty($route['params'])) { unset($matches[0]); $params = array_combine($route['params'], $matches); } $widget = Typecho_Widget::widget($route['widget'], NULL, $params); if (isset($route['action'])) { $widget->{$route['action']}(); } return; } catch (Exception $e) { if (404 == $e->getCode()) { Typecho_Widget::destory($route['widget']); continue; } throw $e; } } } /** 载入路由异常支持 */ require_once 'Typecho/Router/Exception.php'; throw new Typecho_Router_Exception("Path '{$pathInfo}' not found", 404); }
/** * 路由分发函数 * * @param string $path 目的文件所在目录 * @return void * @throws Typecho_Route_Exception */ public static function dispatch() { /** 获取PATHINFO */ $pathInfo = self::getPathInfo(); // 后台URL修改,收录的URL不能访问,临时处理302 //echo $pathInfo; exit; if (preg_match('/^\\/archives\\/\\d*\\/?$/isU', $pathInfo)) { if (substr($pathInfo, -1) == '/') { $pathInfo = substr($pathInfo, 0, -1); } header('Location:http://blog.chromev.com' . $pathInfo . '.html', true, 302); exit; } foreach (self::$_routingTable as $key => $route) { if (preg_match($route['regx'], $pathInfo, $matches)) { self::$current = $key; try { /** 载入参数 */ $params = NULL; if (!empty($route['params'])) { unset($matches[0]); $params = array_combine($route['params'], $matches); } $widget = Typecho_Widget::widget($route['widget'], NULL, $params); if (isset($route['action'])) { $widget->{$route['action']}(); } return; } catch (Exception $e) { if (404 == $e->getCode()) { Typecho_Widget::destory($route['widget']); continue; } throw $e; } } } /** 载入路由异常支持 */ throw new Typecho_Router_Exception("Path '{$pathInfo}' not found", 404); }