Web\Url: add a shift() method

This methods allows to retrieve an URL param while removing it from the
URL object
This commit is contained in:
Thomas Gelf 2014-05-20 13:49:35 +00:00
parent 358b2582bc
commit 4e88a4e008
1 changed files with 19 additions and 0 deletions

View File

@ -463,6 +463,25 @@ class Url
return $this; 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 * Return a copy of this url without the parameter given
* *