diff --git a/Uri/UriFactory.php b/Uri/UriFactory.php index 751b1ec1b..7e234fcdd 100644 --- a/Uri/UriFactory.php +++ b/Uri/UriFactory.php @@ -87,6 +87,33 @@ class UriFactory return false; } + private static function unique(string $url) : string + { + $parts = explode('?', url); + + if (count($parts) >= 2) { + $full = $parts[1]; + $pars = explode('&', $full), + $comps = [], + $spl = null, + $length = count($pars); + + for ($i = 0; $i < $length; $i++) { + $spl = explode('=', $pars[i]); + $comps[$spl[0]] = $spl[1]; + } + + $pars = []; + foreach($comps as $key => $value) { + $pars[] = $key . '=' . $value; + } + + $url = $parts[0] . '?' . implode('&', $pars); + } + + return $url; + } + /** * Build uri. * @@ -109,10 +136,19 @@ class UriFactory */ public static function build(string $uri, array $toMatch = []) { - return preg_replace_callback('(\{[\/#\?@\.\$][a-zA-Z0-9\-]*\})', function ($match) use ($toMatch) { + $parsed = preg_replace_callback('(\{[\/#\?@\.\$][a-zA-Z0-9\-]*\})', function ($match) use ($toMatch) { $match = substr($match[0], 1, strlen($match[0]) - 2); return $toMatch[$match] ?? self::$uri[$match] ?? $match; }, $uri); + + // todo: maybe don't do this and adjust unique?! + if(strpos($parsed, '?')) { + str_replace('&', '?', $parsed); + } + + $parsed = self::uniqid($parsed); + + return $parsed; } }