public function constructUrl($getItems, $encodeAmpersand, $encodeGetItems)
{
if ($this->_constants) {
foreach ($this->_constants->toArray() as $key => $value) {
unset($getItems[$key]);
}
}
$extra = array();
$replace = array();
// for the GET variables matching the pattern, put them in the URL path
foreach ($getItems as $key => $value) {
if ($this->_parameters && $this->_parameters->contains($key) || $key === '*' && $this->getIsWildCardPattern()) {
$replace['{' . $key . '}'] = $encodeGetItems ? rawurlencode($value) : $value;
} else {
$extra[$key] = $value;
}
}
$url = $this->_manager->getUrlPrefix() . '/' . ltrim(strtr($this->getPattern(), $replace), '/');
// for the rest of the GET variables, put them in the query string
if (count($extra) > 0) {
if ($this->_urlFormat === THttpRequestUrlFormat::Path && $this->getIsWildCardPattern()) {
foreach ($extra as $name => $value) {
$url .= '/' . $name . $this->_separator . ($encodeGetItems ? rawurlencode($value) : $value);
}
return $url;
}
$url2 = '';
$amp = $encodeAmpersand ? '&' : '&';
if ($encodeGetItems) {
foreach ($extra as $name => $value) {
if (is_array($value)) {
$name = rawurlencode($name . '[]');
foreach ($value as $v) {
$url2 .= $amp . $name . '=' . rawurlencode($v);
}
} else {
$url2 .= $amp . rawurlencode($name) . '=' . rawurlencode($value);
}
}
} else {
foreach ($extra as $name => $value) {
if (is_array($value)) {
foreach ($value as $v) {
$url2 .= $amp . $name . '[]=' . $v;
}
} else {
$url2 .= $amp . $name . '=' . $value;
}
}
}
$url = $url . '?' . substr($url2, strlen($amp));
}
return $this->applySecureConnectionPrefix($url);
}