|
|
@@ -17,6 +17,7 @@ namespace Cake\Routing;
|
|
|
use Cake\Routing\Exception\DuplicateNamedRouteException;
|
|
|
use Cake\Routing\Exception\MissingRouteException;
|
|
|
use Cake\Routing\Route\Route;
|
|
|
+use Psr\Http\Message\ServerRequestInterface;
|
|
|
|
|
|
/**
|
|
|
* Contains a collection of routes.
|
|
|
@@ -148,6 +149,45 @@ class RouteCollection
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * Takes the ServerRequestInterface, iterates the routes until one is able to parse the route.
|
|
|
+ *
|
|
|
+ * @param \Psr\Http\Messages\ServerRequestInterface $request The request to parse route data from.
|
|
|
+ * @return array An array of request parameters parsed from the URL.
|
|
|
+ * @throws \Cake\Routing\Exception\MissingRouteException When a URL has no matching route.
|
|
|
+ */
|
|
|
+ public function parseRequest(ServerRequestInterface $request)
|
|
|
+ {
|
|
|
+ $method = $request->getMethod();
|
|
|
+ $uri = $request->getUri();
|
|
|
+ $urlPath = $uri->getPath();
|
|
|
+ foreach (array_keys($this->_paths) as $path) {
|
|
|
+ if (strpos($urlPath, $path) !== 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ $host = $uri->getHost();
|
|
|
+ /* @var \Cake\Routing\Route\Route $route */
|
|
|
+ foreach ($this->_paths[$path] as $route) {
|
|
|
+ if (!$route->hostMatches($host)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ $r = $route->parse($urlPath, $method);
|
|
|
+ if ($r === false) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if ($uri->getQuery()) {
|
|
|
+ parse_str($uri->getQuery(), $queryParameters);
|
|
|
+ $r['?'] = $queryParameters;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $r;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ throw new MissingRouteException(['url' => $url]);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* Get the set of names from the $url. Accepts both older style array urls,
|
|
|
* and newer style urls containing '_name'
|
|
|
*
|