Get the URL of a named route

@param  string $name
@param  array  $args

@return string

@throws Exception If there aren't enough arguments for all required parameters
171898
public function getRoute($name, array $args = [])
    {
        if (!isset($this->names[$name])) {
            return null;
        }

        $route = $this->callbacks[$this->names[$name]];

        if (strpos($route->pattern, '(') === false) {
            // If we don't have any route parameters, just return the pattern
            // straight off. No need for any regex stuff.
            return $route->pattern;
        }

        // Convert all placeholders to %o = optional and %r = required
        $from    = ['/(\([^\/]+[\)]+[\?])/', '/(\([^\/]+\))/'];
        $to      = ['%o', '%r'];
        $pattern = preg_replace($from, $to, $route->pattern);

        $frags = explode('/', trim($pattern, '/'));
        $url   = [];

        // Loop thru the pattern fragments and insert the arguments
        foreach ($frags as $frag) {
            if ($frag == '%r') {
                if (!$args) {
                    // A required parameter, but no more arguments.
                    throw new Exception('Missing route parameters');
                }
                $url[] = array_shift($args);
                continue;
            }

            if ($frag == "%o") {
                if (!$args) {
                    // No argument for the optional parameter,
                    // just continue the iteration.
                    continue;
                }
                $url[] = array_shift($args);
                continue;
            }

            $url[] = $frag;
        }

        return '/' . implode('/', $url);
    }
1014363
public static function page($name = "", $args = []) {
		if (Router::$context == "")
			$path = "/".$name;
		else
			$path = Router::$context."/".$name;

		$path = str_replace("root/", "", $path);

		//Add to routes
		Router::$routes[$path] = array_merge(Router::$stackedOptions, $args);
	}
552246
public function generate($routeName, array $params = array())
    {
        // Check if route exists
        if (!isset($this->namedRoutes[$routeName])) {
            throw new Exception("No route with the name $routeName has been found.");
        }

        /** @var \PHPRouter\Route $route */
        $route = $this->namedRoutes[$routeName];
        $url = $route->getUrl();

        // replace route url with given parameters
        if ($params && preg_match_all('/:(\w+)/', $url, $param_keys)) {
            // grab array with matches
            $param_keys = $param_keys[1];

            // loop trough parameter names, store matching value in $params array
            foreach ($param_keys as $key) {
                if (isset($params[$key])) {
                    $url = preg_replace('/:'.preg_quote($key,'/').'/', $params[$key], $url, 1);
                }
            }
        }

        return $url;
    }
444271
public function getPath($name, array $parameters = array())
    {
        return $this->container->get('router.url_generator')->generate($name, $parameters, false);
    }
394412
public function getUrlFromName($name)
    {
        $searchEngineNames = $this->getNames();
        if (isset($searchEngineNames[$name])) {
            $url = 'http://' . $searchEngineNames[$name];
        } else {
            $url = 'URL unknown!';
        }
        return $url;
    }
571281
public function getUrl($name, $parameters = [], $schemeRelative = false)
    {
        return $this->generator->generate($name, $parameters, $schemeRelative ? UrlGeneratorInterface::NETWORK_PATH : UrlGeneratorInterface::ABSOLUTE_URL);
    }
352994
public function pathFor($name, $vars = [], array $options = [])
    {
        if ($name == 'base') {
            return $this->basePath;
        }
        
        foreach ($this->routes as $route) {
            $route->build();
            
            if ($route->name() == $name) {
                if ($path = $this->buildRouteUrl($route, $vars, $options)) {
                    return $path;
                }
            }
        }
        
        $routeParams = [];
        if (is_array($vars)) {
            $routeParams = array_merge($routeParams, $vars);
        } elseif ($vars instanceof Base) {
            $routeParams['record'] = get_class($vars);
            $routeParams['id'] = $vars->id();
        }
        
        $routeParams = implode(', ', array_map(function($name, $val) { return $name . '=>' . $val; }, array_keys($routeParams), $routeParams));
        $message = "Couldn't find route with name '%s' and options { %s }";
        throw new Exception\InvalidArgumentException(sprintf(
            $message,
            $name,
            $routeParams
        ));
    }
962990
public function getArg(string $name)
    {
        if (!is_array($this->args)) {
            throw new \LogicException(sprintf("Ask for arg '%s' before the router init is finished", $name));
        }

        return $this->args[$name] ?? null;
    }
1088108
protected function routeRemainingMethod($name, array $arguments)
    {
        // If we still have something left, let's figure out what it is
        if ($this->router->exists($name)) {
            $obj = $this->buildTerminalObject($name, $arguments);

            // If something was returned, return it
            if (is_object($obj)) {
                return $obj;
            }
        } elseif ($this->settings->exists($name)) {
            $this->settings->add($name, reset($arguments));
        // Handle passthroughs to the arguments manager.
        } else {
            // If we can't find it at this point, let's fail gracefully
            $this->out(reset($arguments));
        }
    }
920446
protected function getUrlFromRoute($name, Route $route)
    {
        $option = $route->getOption('sitemap');
        
        if ($option === null) {
            return null;
        }
        if (is_string($option)) {
            $decoded = json_decode($option, true);
            if (!json_last_error() && is_array($decoded)) {
                $option = $decoded;
            }
        }
        if (!is_array($option) && !is_bool($option)) {
            $bool = filter_var($option, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
            if (null === $bool) {
                throw new \InvalidArgumentException("The sitemap option for route $name must be boolean or array");
            }
            $option = $bool;
        }
        if (!$option) {
            return null;
        }
        $url = $this->router->generate($name);
        
        $urlObject = new Url(
                $url,
                (isset($option['lastMod']) ? $option['lastMod'] : null),
                (isset($option['priority']) ? $option['priority'] : null),
                (isset($option['changeFreq']) ? $option['changeFreq'] : null)
        );
        
        return $urlObject;
    }
842089
public function get( array $args = [], array $assoc_args = [] ) {

		$site_id = (int) $args[ 0 ];
		$site    = get_blog_details( $site_id );
		if ( ! $site ) {
			WP_CLI::error( "A site with ID {$site_id} does not exist" );
		}

		// trailing-slash it, as URLs ends always with a trailing slash in context of the wp_blogs table
		WP_CLI::line( trailingslashit( $site->siteurl ) );
		exit( 0 );
	}
359480
public function getArgument($name, $mode = self::MODE_THROW_EXCEPTION_ON_ERROR)
    {
        $this->checkGetMode($mode, __METHOD__);

        if (false === $this->hasArgument($name)) {
            if ($mode === static::MODE_THROW_EXCEPTION_ON_ERROR) {
                throw new InvalidNameException(sprintf("The argument name '%s' doesn't exist", $name));
            } elseif ($mode === static::MODE_RETURN_BOOLEAN) {
                return false;
            } elseif ($mode === static::MODE_RETURN_NULL) {
                return;
            }
        }

        return $this->collection[$name];
    }
95803
public function referenceObject(string $name, array $args): JavaProxy
    {
        $this->protocol->referenceBegin($name);
        $this->writeArgs($args);
        $this->protocol->referenceEnd();
        $val = $this->getInternalResult();

        return $val;
    }
882669
public static function url( array $args = [], string $url = null ) {
		if ( is_null( $url ) ) {
			$url = $_SERVER['REQUEST_URI'];
		}

		return add_query_arg( $args, $url );
	}
279598
public function getRoute(string $name = null, ...$args)
    {
        if (is_null($name)) {
            return $this->get('route');
        }

        return $this->get('route', $name, ...$args);
    }
1086813
public function _as($name)
    {
        if (empty($name)) return $this;
        $name = rtrim($this->getGroupAs() . str_replace('/', '.', strtolower($name)), '.');
//        if (array_key_exists($name, $this->routes)) {
//            throw new \Exception("Route name ($name) already registered.");
//        }

        $patt = $this->patt;
        $pram = $this->prams;
        // Merge group parameters with route parameters.
        if ($this->isGroup) {
            $patt = array_merge($this->pattGroup, $patt);
            if (count($patt) > count($pram)) {
                $pram = array_merge($this->pramsGroup, $pram);
            }
        }

        // :param
        if (count($pram)) {
            foreach ($pram as $k => $v) {
                $pram[$k] = '/:' . $v;
            }
        }

        // Replace pattern to named parameters.
        $replaced = $this->group . $this->currentUri;
        foreach ($patt as $k => $v) {
            $pos = strpos($replaced, $v);
            if ($pos !== false) {
                $replaced = substr_replace($replaced, $pram[$k], $pos, strlen($v));
            }
        }

        $this->routes[$name] = ltrim($this->removeDuplSlash(strtolower($replaced)), '/');

        return $this;
    }
121525
public function callRoute($name, array $parameters = [], array $options = [])
    {
        try {
            $content = $this->router->dispatchRoute($name, $parameters, $options);
        } catch (\Exception $e) {
            return sprintf('<p style="display:block;boder:1px solid red;" class="error">%s</p>', $e->getMessage());
        }

        return is_string($content) ? $content : '';
    }