/** * {@inheritdoc} */ public function generate($name, array $parameters = [], $host = null, $type = self::RELATIVE_PATH) { if (null === $this->routes || !($route = $this->routes->get($name))) { throw new \InvalidArgumentException(sprintf('A route with name "%s" could not be found.', $name)); } return $this->compilePath($route, $parameters, $host ?: $route->getHost(), $type, $name); }
/** * createMatchContextFromParameters * * @param array $parameters * @param string $url * * @return MatchContextInterface */ private function createMatchContextFromParameters(array $vars, $name, $request) { $handler = $this->routes->get($name)->getHandler(); return new MatchContext(Matcher::MATCH, $name, $request, $handler, $vars); }
/** * reverseMapRoute * * @param RouteCollectionInterface $routes * @param array $matches * @param array $map * * @return array [Lucid\Mux\RouteInterface, array] */ private function reverseMapRoute(RouteCollectionInterface $routes, array $matches, array $map = []) { foreach ($matches = array_filter($matches[0]) as $key => $subject) { if (is_int($key)) { continue; } if (!isset($map[$key])) { continue; } list($index, $name, $prefix) = $map[$key]; try { $route = $routes->get($name); } catch (\Exception $e) { throw new RuntimeException('Route does not exists.'); } $route = $routes->get($name); $args = []; $keys = $route->getContext()->getVars(); $args = array_combine($keys, array_map(function ($key) use($matches, $prefix) { return isset($matches[$prefix . $key]) ? $this->getArgValue($matches[$prefix . $key]) : null; }, $keys)); return [$name, $route, array_merge($route->getDefaults(), array_filter($args))]; } throw new RuntimeException('No match found.'); }