/**
* Set url query param.
*
* @param StringObject|ArrayObject|string|array $query Query params.
* @param bool $append Do you want to append or overwrite current query param.
* In case when you are appending values, the values from $query,
* that already exist in the current query, will be overwritten
* by the ones inside the $query.
*
* @throws UrlObjectException
* @return $this
*/
public function setQuery($query, $append = false)
{
if ($this->isStdObject($query)) {
$query = $query->val();
}
if ($append && $this->query != '') {
if ($this->isString($this->query)) {
$currentQuery = new StringObject($this->query);
$currentQuery = $currentQuery->parseString();
} else {
$currentQuery = new ArrayObject($this->query);
}
if ($this->isStdObject($query)) {
if (StdObjectWrapper::isArrayObject($append)) {
$query = $query->val();
} else {
if (StdObjectWrapper::isStringObject($query)) {
$query = $query->parseString()->val();
} else {
throw new UrlObjectException(UrlObjectException::MSG_INVALID_ARG, ['$query', 'StringObject|ArrayObject|string|array']);
}
}
} else {
if ($this->isString($query)) {
$query = new StringObject($query);
$query = $query->parseString()->val();
}
}
$currentQuery->merge($query);
$query = $currentQuery->val();
}
$this->query = $query;
$this->rebuildUrl();
return $this;
}