From 703ad99464751a2e9452c028b19624e978a6ef04 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 31 Jan 2020 19:39:15 -0500 Subject: [PATCH] Add Util\Network::appendQueryParam method --- src/Util/Network.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/Util/Network.php b/src/Util/Network.php index e2cfc3e849..17ddd048a5 100644 --- a/src/Util/Network.php +++ b/src/Util/Network.php @@ -870,4 +870,27 @@ class Network return $url; } + + /** + * Adds query string parameters to the provided URI. Replace the value of existing keys. + * + * @param string $path + * @param array $additionalParams Associative array of parameters + * @return string + */ + public static function appendQueryParam(string $path, array $additionalParams) + { + $parsed = parse_url($path); + + $params = []; + if (!empty($parsed['query'])) { + parse_str($parsed['query'], $params); + } + + $params = array_merge($params, $additionalParams); + + $parsed['query'] = http_build_query($params); + + return self::unparseURL($parsed); + } }