/** * {@inheritdoc} */ public function createUri($route, $parameters = [], SlugifyInterface $slugify = null) { if (isset($this->routes[$route])) { return $this->routes[$route]->createUri($parameters, $this->basePath, $slugify); } //Will be handled via default route where route name is specified as controller::action if (strpos($route, RouteInterface::SEPARATOR) === false && strpos($route, '/') === false) { throw new RouterException("Unable to locate route or use default route with controller::action pattern."); } //We can fetch controller and action names from url list($controller, $action) = explode(RouteInterface::SEPARATOR, str_replace('/', RouteInterface::SEPARATOR, $route)); return $this->defaultRoute->createUri(compact('controller', 'action') + $parameters, $this->basePath, $slugify); }
/** * @param string $route * @return RouteInterface * @throws UndefinedRouteException */ private function castRoute($route) { //Will be handled via default route where route name is specified as controller::action if (strpos($route, ':') === false) { throw new UndefinedRouteException("Unable to locate route or use default route with 'controller:action' pattern."); } if (empty($this->defaultRoute)) { throw new UndefinedRouteException("Default/fallback route is missing."); } //We can fetch controller and action names from url list($controller, $action) = explode(':', str_replace(['/', '::'], ':', $route)); $route = $this->defaultRoute->withName($route)->withDefaults(['controller' => $controller, 'action' => $action]); //For future requests $this->addRoute($route); return $route; }
/** * Get vault specific uri. * * @param string $target Target controller and action in a form of "controller::action" or * "controller:action" or "controller". * @param array|mixed $parameters * @return UriInterface * @throws VaultException */ public function uri($target, $parameters = []) { $controller = $action = ''; if (strpos($target, ':') !== false) { list($controller, $action) = explode(':', $target); } else { $controller = $target; if (!empty($parameters)) { throw new VaultException("Unable to generate uri with empty controller action and not empty parameters."); } } if (!isset($this->config->controllers()[$controller])) { throw new VaultException("Unable to generate uri, undefined controller '{$controller}'."); } return $this->route->withDefaults(compact('controller', 'action'))->uri($parameters); }
/** * Get vault specific uri. * * @param string $target Target controller and action in a form of "controller::action" or * "controller:action" or "controller". * @param array|mixed $parameters * @return UriInterface * @throws VaultException */ public function uri($target, $parameters = []) { $target = str_replace('::', ':', $target); $controller = $action = ''; if (strpos($target, ':') !== false) { list($controller, $action) = explode(':', $target); } else { $controller = $target; if (!empty($parameters)) { throw new VaultException("Unable to generate uri with empty controller action and not empty parameters."); } } if (!isset($this->config->controllers()[$controller])) { throw new VaultException("Unable to generate uri, undefined controller '{$controller}'."); } $parameters['controller'] = $controller; $parameters['action'] = $action; return $this->route->uri($parameters, $this->httpConfig->basePath()); }