/** * 路由解析 * * 匹配这个patten时,将试图去解析module、controller和action值,并解析二级域名。 * @see AbstractWindRoute::match() */ public function match($request) { $fullUrl = $request->getHostInfo() . $request->getRequestUri(); $_pathInfo = trim(str_replace($request->getBaseUrl(), '', $fullUrl), '/'); if (!$_pathInfo || !preg_match_all('/' . $this->pattern . '/i', trim($_pathInfo, '/'), $matches) || strpos($_pathInfo, '.php') !== false) { return null; } list(, $_args) = explode('?', $_pathInfo . '?', 2); $_args = trim($_args, '?'); $_args = WindUrlHelper::urlToArgs($_args, true, $this->separator); foreach ($this->params as $_n => $_p) { if (isset($_p['map']) && isset($matches[$_p['map']][0])) { $_value = $matches[$_p['map']][0]; } else { $_value = isset($_p['default']) ? $_p['default'] : ''; } $this->params[$_n]['value'] = $params[$_n] = trim($_value, '-/'); unset($_args[$_n]); //去掉参数中的m,c,a } $host = $request->getHostInfo(); if ($host != '' && ($pos1 = strpos($host, '://')) !== false && ($pos2 = strpos($host, '.')) !== false) { $host = substr($host, $pos1 + 3, $pos2 - $pos1 - 3); } else { return null; } $params['p'] = $host == 'www' ? '' : $host; unset($_args['p']); //去掉参数中的p $_args && ($params = array_merge($params, $_args)); return $params; }
/** * 分析参数 * * @param AbstractWindRouter $router * @param string $action * @param array $args * @return array */ private function _resolveMca($router, $action, $args) { list($action, $_args) = explode('?', $action . '?'); $args = array_merge($args, $_args ? WindUrlHelper::urlToArgs($_args, false) : array()); $action = trim($action, '/'); $tmp = explode('/', $action . '/'); end($tmp); if (5 === count($tmp) && !strncasecmp('app/', $action, 4)) { list($_a, $_c, $_app_name, $_m) = array(prev($tmp), prev($tmp), prev($tmp), prev($tmp)); $args['app'] = $_app_name; } else { list($_a, $_c, $_m) = array(prev($tmp), prev($tmp), prev($tmp)); } return array($_a, $_c, $_m, $args); }
/** * 路由解析 * * 匹配这个patten时,将试图去解析module、controller和action值,并解析二级域名。 * * @see AbstractWindRoute::match() */ public function match($request) { $_pathInfo = trim($request->getPathInfo(), '/'); if (!$_pathInfo || !preg_match($this->pattern, $_pathInfo, $matches) || strpos($_pathInfo, '.php') !== false) { return null; } $params = array(); $_args = WindUrlHelper::urlToArgs($matches[4], true, $this->separator); // 解析m,c,a foreach ($this->params as $k => $v) { if (isset($matches[$v])) { $params[$k] = trim($matches[$v], '-/'); } unset($_args[$k]); // 去掉参数中的m,c,a } return $_args + $params; }
/** * 分析参数 * * @param AbstractWindRouter $router * @param string $action * @param array $args * @return array */ private function _resolveMca($router, $action, $args) { list($action, $_args) = explode('?', $action . '?'); $args = array_merge($args, $_args ? WindUrlHelper::urlToArgs($_args, false) : array()); $action = trim($action, '/'); $tmp = explode('/', $action . '/'); end($tmp); if (5 === count($tmp) && !strncasecmp('app/', $action, 4)) { list($_a, $_c, $_app_name, $_m) = array(prev($tmp), prev($tmp), prev($tmp), prev($tmp)); $args['app'] = $_app_name; } else { list($_a, $_c, $_m) = array(prev($tmp), prev($tmp), prev($tmp)); } $_m = $_m ? $_m : $router->getDefaultModule(); $_c = $_c ? $_c : $router->getDefaultController(); $_a = $_a ? $_a : $router->getDefaultAction(); return array($_m, $_c, $_a, $args); }
/** * 过滤来源URL * * TODO * * @return string */ private function _filterUrl($returnDefault = true) { $url = $this->getInput('backurl'); if (!$url) { $url = $this->getRequest()->getServer('HTTP_REFERER'); } if ($url) { // 排除来自注册页面/自身welcome/show的跳转 $args = WindUrlHelper::urlToArgs($url); if ($args['m'] == 'u' && in_array($args['c'], array('register', 'login'))) { $url = ''; } } if (!$url && $returnDefault) { $url = Wekit::url()->base; } return $url; }
public function match($request) { $path = $request->getPathInfo(); return WindUrlHelper::urlToArgs($path); }