/** * Generates a path for route given. * * @param string $name * @param array $params * * @return string */ public function path($name, array $params = []) { $route = $this->routeContainer->get($name); $paramNames = array_map(function ($param) { return ":{$param}"; }, array_keys($params)); $path = str_replace($paramNames, array_values($params), $route->path); return $path; }
/** * Decides which action should be taken for request passed. * * @param Request $request * * @throws \Exception When it can't resolve action * * @return ResolvedAction */ public function resolve(Request $request) { $path = $request->getPathInfo(); foreach ($this->routeContainer->getAll() as $route) { $parameters = $this->match($path, $request->getMethod(), $route); if (null !== $parameters) { list($controllerClass, $controllerMethod) = explode('#', $route->controller); $controller = new $controllerClass($request, $this->container); $resolvedAction = new ResolvedAction(); $resolvedAction->callable = [$controller, $controllerMethod]; $resolvedAction->parameters = $parameters; return $resolvedAction; } } throw new \Exception(sprintf('Could not match request %s %s to any controller', $request->getMethod(), $path)); }