mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-26 23:34:08 +02:00
Url: Add method onlyWith()
This commit is contained in:
parent
b083b544f5
commit
46c6201a21
@ -828,6 +828,32 @@ class Url
|
|||||||
return $url;
|
return $url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a copy of this url with only the given parameter(s)
|
||||||
|
*
|
||||||
|
* The argument can be either a single query parameter name or
|
||||||
|
* an array of parameter names to keep on on the query
|
||||||
|
*
|
||||||
|
* @param string|array $keyOrArrayOfKeys
|
||||||
|
*
|
||||||
|
* @return static
|
||||||
|
*/
|
||||||
|
public function onlyWith($keyOrArrayOfKeys)
|
||||||
|
{
|
||||||
|
if (! is_array($keyOrArrayOfKeys)) {
|
||||||
|
$keyOrArrayOfKeys = [$keyOrArrayOfKeys];
|
||||||
|
}
|
||||||
|
|
||||||
|
$url = clone $this;
|
||||||
|
foreach ($url->getParams()->toArray(false) as $key => $_) {
|
||||||
|
if (! in_array($key, $keyOrArrayOfKeys, true)) {
|
||||||
|
$url->remove($key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $url;
|
||||||
|
}
|
||||||
|
|
||||||
public function __clone()
|
public function __clone()
|
||||||
{
|
{
|
||||||
$this->params = clone $this->params;
|
$this->params = clone $this->params;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user