public function getRoutePath(Route $route, array $params) { $routes = $this->routeParser->parse($route->getPattern()); foreach ($routes as $route) { $path = ''; $index = 0; foreach ($route as $part) { // Fixed segment in the route if (is_string($part)) { $path .= $part; continue; } // Placeholder in the route if ($index === count($params)) { throw new \InvalidArgumentException('Too few parameters given'); } if ($this->validateParams && $part[1] !== '[^/]+') { if (!preg_match("/^{$part[1]}\$/", $params[$index])) { throw new \InvalidArgumentException("Route parameter pattern mismatch: " . "Parameter #{$index} \"{$params[$index]}\" does not match pattern {$part[1]}"); } } $path .= $params[$index++]; } // If number of params in route matches with number of params given, use that route. // Otherwise try to find a route that has more params if ($index === count($params)) { return $path; } } throw new \InvalidArgumentException('Too many parameters given'); }
protected function getContainerParams(Route $route, array $routeParams, Request $request) { $params = []; if ($extraParams = $route->getOption('params')) { $params = $extraParams; } // the container expects a dollar sign in front of non-class function // arguments foreach ($routeParams as $key => $value) { $params["\${$key}"] = $value; } // this allows controllers to type-hint against the Request class to get // access to it directly $params['Symfony\\Component\\HttpFoundation\\Request'] = $request; return $params; }