private function generateUrlPart(string $rawPart, string $regex, string $routeName, &$values) : string
    {
        $generatedPart = $rawPart;
        $count = 1000;

        while ($count > 0 && count($values) > 0) {
            $generatedPart = preg_replace(self::$variableMatchingRegex, $values[0], $generatedPart, 1, $count);

            if ($count > 0) {
                // Only remove a value if we actually replaced something
                array_shift($values);
            }
        }

        // Remove any leftover brackets or variables
        $generatedPart = preg_replace(self::$leftoverBracketsAndVariablesRegex, '', $generatedPart);

        // Make sure what we just generated satisfies the regex
        if (!preg_match($regex, $generatedPart)) {
            throw new UrlException(
                "Generated URL part \"$generatedPart\" does not satisfy regex for route \"$routeName\""
            );
        }

        return $generatedPart;
    }
private function generateUrlPart(string $rawPart, string $regex, string $routeName, &$values) : string
    {
        $generatedPart = $rawPart;
        $count = 1000;

        while ($count > 0 && count($values) > 0) {
            $generatedPart = preg_replace(self::$variableMatchingRegex, $values[0], $generatedPart, 1, $count);

            if ($count > 0) {
                // Only remove a value if we actually replaced something
                array_shift($values);
            }
        }

        // Remove any leftover brackets or variables
        $generatedPart = preg_replace(self::$leftoverBracketsAndVariablesRegex, '', $generatedPart);

        // Make sure what we just generated satisfies the regex
        if (!preg_match($regex, $generatedPart)) {
            throw new UrlException(
                "Generated URL part \"$generatedPart\" does not satisfy regex for route \"$routeName\""
            );
        }

        return $generatedPart;
    }
private function generateUrlPart ( string $ rawPart , string $ regex , string $ routeName , & $ values ) : string { $ generatedPart = $ rawPart ; $ count = 1000 ; while ( $ count > 0 && count ( $ values ) > 0 ) { $ generatedPart = preg_replace ( self :: $ variableMatchingRegex , $ values [ 0 ] , $ generatedPart , 1 , $ count ) ; if ( $ count > 0 ) { // Only remove a value if we actually replaced something array_shift ( $ values ) ; } } // Remove any leftover brackets or variables $ generatedPart = preg_replace ( self :: $ leftoverBracketsAndVariablesRegex , '' , $ generatedPart ) ; // Make sure what we just generated satisfies the regex if ( ! preg_match ( $ regex , $ generatedPart ) ) { throw new UrlException ( "Generated URL part \"$generatedPart\" does not satisfy regex for route \"$routeName\"" ) ; } return $ generatedPart ; }
Generates a part of a URL for a route

@param string $rawPart The raw part to generate
@param string $regex The regex to match against
@param string $routeName The route name
@param mixed|array $values The value or list of values to fill the route with
@return string The generated URL part
@throws UrlException Thrown if the generated path is not valid
Generates a part of a URL for a route