From 4e88a4e0080b364b710d587967e094ca9d9e5322 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Tue, 20 May 2014 13:49:35 +0000 Subject: [PATCH] Web\Url: add a shift() method This methods allows to retrieve an URL param while removing it from the URL object --- library/Icinga/Web/Url.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/library/Icinga/Web/Url.php b/library/Icinga/Web/Url.php index 8476e40ce..e00fad03c 100644 --- a/library/Icinga/Web/Url.php +++ b/library/Icinga/Web/Url.php @@ -463,6 +463,25 @@ class Url return $this; } + /** + * Shift a query parameter from this URL if it exists, otherwise $default + * + * @param string $param Parameter name + * @param mixed $default Default value in case $param does not exist + * + * @return mixed + */ + public function shift($param, $default = null) + { + if (isset($this->params[$param])) { + $ret = $this->params[$param]; + unset($this->params[$param]); + } else { + $ret = $default; + } + return $ret; + } + /** * Return a copy of this url without the parameter given *