mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-15 11:38:40 +00:00
Match urifactory of javascript impl.
This commit is contained in:
parent
42c403a60c
commit
15c4eca1f9
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user