/** * Parse the given URI with the route's pattern to extract the parameters sent by the user * Throws an Exception if the uri does not match the route * * @param Route $route the route matching the uri * @param string $uri the requested URI * * @throws \Exception * * @return array the parameters from the URI */ public function getRouteParams(Route $route, $uri) { if (!$route->matches($uri)) { throw new \Exception("Route doesn't match"); } $params = array(); $routeParts = explode("/", trim($route->getPattern(), "/")); $uriParts = explode("/", trim($uri, "/")); foreach ($routeParts as $index => $part) { if ($part != $uriParts[$index]) { $params[] = $uriParts[$index]; } } return $params; }