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:
parent
358b2582bc
commit
4e88a4e008
|
@ -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
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue