/** * (non-PHPdoc) * @see \tfc\mvc\routes\Route::match() */ public function match(HttpRequest $request) { $controller = $request->getParam($this->_controllerKey); $action = $request->getParam($this->_actionKey); $module = $request->getParam($this->_moduleKey); $this->setController($controller); $this->setAction($action); $this->setModule($module); return true; }
/** * (non-PHPdoc) * @see \tfc\mvc\routes\Route::match() */ public function match(HttpRequest $request) { $path = $request->getParam($this->_routeVar, ''); $path = trim($path, self::URI_DELIMITER . ' '); $bits = explode(self::URI_DELIMITER, $path); switch (count($bits)) { case 2: $this->setController($bits[0]); $this->setAction($bits[1]); break; case 1: $this->setController($bits[0]); break; case 3: default: $this->setModule($bits[0]); $this->setController($bits[1]); $this->setAction($bits[2]); break; } return true; }
/** * (non-PHPdoc) * @see \tfc\mvc\routes\Route::match() */ public function match(HttpRequest $request) { $path = trim($request->pathInfo, self::URI_DELIMITER); $pattern = self::REGEX_DELIMITER . '^' . $this->_pattern . self::REGEX_DELIMITER . 'i'; if (preg_match($pattern, $path, $regs) === 0) { return false; } $path = ltrim(substr($path, strlen($regs[0])), self::URI_DELIMITER); unset($regs[0]); foreach ($regs as $key => $value) { if (!is_int($key)) { unset($regs[$key]); } } foreach (array_merge($this->_defaults, $regs) as $key => $value) { if ($key === 'controller' || $key === 'action' || $key === 'module') { $method = 'set' . $key; $this->{$method}($value); continue; } if (is_int($key) && isset($this->_maps[$key])) { $key = $this->_maps[$key]; } $request->setParam($key, $value); } $bits = explode(self::URI_DELIMITER, $path); $last = count($bits) - 1; if ($last > 0) { for ($pos = 0; $pos < $last; $pos += 2) { $request->setParam($bits[$pos], $bits[$pos + 1]); } } return true; }
/** * (non-PHPdoc) * @see \tfc\mvc\routes\Route::match() */ public function match(HttpRequest $request) { if ($this->_route == '') { return false; } $needMapped = false; if (substr($this->_route, -1) == '*') { $needMapped = true; $this->_route = substr($this->_route, 0, -2); } $regs = $maps = $routes = array(); foreach (explode(self::URI_DELIMITER, $this->_route) as $key => $value) { if (substr($value, 0, 1) == $this->_urlVariable) { $value = substr($value, 1); $maps[$key] = $value; $regs[$key] = isset($this->_regs[$key]) ? $this->_regs[$key] : $this->_defaultRegex; } $routes[$key] = $value; } $bits = explode(self::URI_DELIMITER, trim($request->pathInfo, self::URI_DELIMITER)); foreach ($bits as $key => $value) { if (!isset($routes[$key])) { break; } if (isset($maps[$key])) { if ($regs[$key] !== null && !preg_match(self::REGEX_DELIMITER . '^' . $regs[$key] . '$' . self::REGEX_DELIMITER . 'iu', $value)) { return false; } $this->_defaults[$maps[$key]] = $value; continue; } if ($routes[$key] !== $value) { return false; } unset($bits[$key]); } foreach ($this->_defaults as $key => $value) { if ($key === 'controller' || $key === 'action' || $key === 'module') { $method = 'set' . $key; $this->{$method}($value); continue; } if (is_int($key) && isset($maps[$key])) { $key = $maps[$key]; } $request->setParam($key, $value); } // 取字符串':module/:controller/:action/*'中"*"后面的内容,填充request::params值 if ($needMapped) { $bits = array_values($bits); $last = count($bits) - 1; if ($last > 0) { for ($pos = 0; $pos < $last; $pos += 2) { $request->setParam($bits[$pos], $bits[$pos + 1]); } } } return true; }