public function getPathFor($route_name, array $params = null, $flatten_regex = true)
    {
        // First, grab the route
        $route = $this->routes->get($route_name);

        // Make sure we are getting a valid route
        if (null === $route) {
            throw new OutOfBoundsException('No such route with name: '. $route_name);
        }

        $path = $route->getPath();

        // Use our compilation regex to reverse the path's compilation from its definition
        $reversed_path = preg_replace_callback(
            static::ROUTE_COMPILE_REGEX,
            function ($match) use ($params) {
                list($block, $pre, , $param, $optional) = $match;

                if (isset($params[$param])) {
                    return $pre. $params[$param];
                } elseif ($optional) {
                    return '';
                }

                return $block;
            },
            $path
        );

        // If the path and reversed_path are the same, the regex must have not matched/replaced
        if ($path === $reversed_path && $flatten_regex && strpos($path, '@') === 0) {
            // If the path is a custom regular expression and we're "flattening", just return a slash
            $path = '/';
        } else {
            $path = $reversed_path;
        }

        return $path;
    }
public function getPathFor($route_name, array $params = null, $flatten_regex = true)
    {
        // First, grab the route
        $route = $this->routes->get($route_name);

        // Make sure we are getting a valid route
        if (null === $route) {
            throw new OutOfBoundsException('No such route with name: '. $route_name);
        }

        $path = $route->getPath();

        // Use our compilation regex to reverse the path's compilation from its definition
        $reversed_path = preg_replace_callback(
            static::ROUTE_COMPILE_REGEX,
            function ($match) use ($params) {
                list($block, $pre, , $param, $optional) = $match;

                if (isset($params[$param])) {
                    return $pre. $params[$param];
                } elseif ($optional) {
                    return '';
                }

                return $block;
            },
            $path
        );

        // If the path and reversed_path are the same, the regex must have not matched/replaced
        if ($path === $reversed_path && $flatten_regex && strpos($path, '@') === 0) {
            // If the path is a custom regular expression and we're "flattening", just return a slash
            $path = '/';
        } else {
            $path = $reversed_path;
        }

        return $path;
    }
public function getPathFor ( $ route_name , array $ params = null , $ flatten_regex = true ) { // First, grab the route $ route = $ this -> routes -> get ( $ route_name ) ; // Make sure we are getting a valid route if ( null === $ route ) { throw new OutOfBoundsException ( 'No such route with name: ' . $ route_name ) ; } $ path = $ route -> getPath ( ) ; // Use our compilation regex to reverse the path's compilation from its definition $ reversed_path = preg_replace_callback ( static :: ROUTE_COMPILE_REGEX , function ( $ match ) use ( $ params ) { list ( $ block , $ pre , , $ param , $ optional ) = $ match ; if ( isset ( $ params [ $ param ] ) ) { return $ pre . $ params [ $ param ] ; } elseif ( $ optional ) { return '' ; } return $ block ; } , $ path ) ; // If the path and reversed_path are the same, the regex must have not matched/replaced if ( $ path === $ reversed_path && $ flatten_regex && strpos ( $ path , '@' ) === 0 ) { // If the path is a custom regular expression and we're "flattening", just return a slash $ path = '/' ; } else { $ path = $ reversed_path ; } return $ path ; }
Get the path for a given route

This looks up the route by its passed name and returns
the path/url for that route, with its URL params as
placeholders unless you pass a valid key-value pair array
of the placeholder params and their values

If a pathname is a complex/custom regular expression, this
method will simply return the regular expression used to
match the request pathname, unless an optional boolean is
passed "flatten_regex" which will flatten the regular
expression into a simple path string

This method, and its style of reverse-compilation, was originally
inspired by a similar effort by Gilles Bouthenot (@gbouthenot)

@link https://github.com/gbouthenot
@param string $route_name        The name of the route
@param array $params             The array of placeholder fillers
@param boolean $flatten_regex    Optionally flatten custom regular expressions to "/"
@throws OutOfBoundsException     If the route requested doesn't exist
@return string
Get the path for a given route