70 $path = urldecode($this->
getUriPath($request));
72 foreach ($this->routes as $route)
74 if ($matchResult = $route->match($path))
77 if (!empty($route->getOptions()->getMethods())
78 && !in_array($request->getRequestMethod(), $route->getOptions()->getMethods(),
true))
83 if (is_array($matchResult))
85 $route->getParametersValues()->setValues($matchResult);
102 '?'.$request->getServer()->get(
'QUERY_STRING'),
104 $request->getRequestUri()
108 $scheme = $request->isHttps() ?
'https://' :
'http://';
109 $schemeLen = strlen($scheme);
111 if (substr($path, 0, $schemeLen) === $scheme)
113 $pathSlashPos = strpos(substr($path, $schemeLen),
'/') + $schemeLen;
114 $path = substr($path, $pathSlashPos);
133 public function route($name, $parameters = [])
135 if (!empty($this->routesByName[$name]))
138 $route = $this->routesByName[$name];
141 $uri = $route->getUri();
143 if (!empty($routeParameters = $route->getParameters()))
145 foreach ($routeParameters as $parameterName => $pattern)
147 if (array_key_exists($parameterName, $parameters))
150 $value = $parameters[$parameterName];
153 unset($parameters[$parameterName]);
155 elseif ($route->getOptions() && $route->getOptions()->hasDefault($parameterName))
157 $value = $route->getOptions()->getDefault($parameterName);
166 $uri = str_replace(
"{{$parameterName}}", urlencode($value), $uri);
171 if (!empty($parameters))
173 $uri .=
'?'.http_build_query($parameters);