Url::add_url_parameter(): make $value parameter optional

This commit is contained in:
Benjamin Renard 2024-11-25 11:04:37 +01:00
parent 5b54abb7af
commit 23a40c9680
Signed by: bn8
GPG key ID: 3E2E1CE1907115BC

View file

@ -538,17 +538,21 @@ class Url {
* *
* @param string $url The URL * @param string $url The URL
* @param string $parameter The parameter name * @param string $parameter The parameter name
* @param string $value The parameter value * @param string|null $value The parameter value (optional)
* @param boolean $encode Set if parameter value must be URL encoded (optional, default: true) * @param boolean $encode Set if parameter value must be URL encoded (optional, default: true)
* *
* @return string The completed URL * @return string The completed URL
*/ */
public static function add_url_parameter($url, $parameter, $value, $encode=true) { public static function add_url_parameter($url, $parameter, $value=null, $encode=true) {
if (strpos($url, '?') === false) if (strpos($url, '?') === false)
$url .= '?'; $url .= '?';
else else
$url .= '&'; $url .= '&';
$url .= "$parameter=".($encode?urlencode($value):$value); $url .= (
is_null($value)?
$parameter:
"$parameter=".($encode?urlencode($value):$value)
);
return $url; return $url;
} }