private static function encodeUrl($url)
{
$url_parsed = parse_url($url);
$scheme = $url_parsed['scheme'] . '://';
$host = $url_parsed['host'];
$port = isset($url_parsed['port']) ? $url_parsed['port'] : null;
$path = isset($url_parsed['path']) ? $url_parsed['path'] : null;
$query = isset($url_parsed['query']) ? $url_parsed['query'] : null;
if ($query !== null) {
$query = '?' . http_build_query(self::getArrayFromQuerystring($query));
}
if ($port && $port[0] !== ':') {
$port = ':' . $port;
}
$result = $scheme . $host . $port . $path . $query;
return $result;
}