Convert a full SSH URL (with schema) into a normal SSH connection string.

@param string $url             The URL (starting with ssh://).
@param string $username_suffix A suffix to append to the username.

@return string
173732
private function convertSshUrl($url, $username_suffix = '')
    {
        $parsed = parse_url($url);
        if (!$parsed) {
            throw new \InvalidArgumentException('Invalid URL: ' . $url);
        }

        return $parsed['user'] . $username_suffix . '@' . $parsed['host'];
    }
306477
public static function rstrip($str, $suffix)
    {
        if (substr($str, -strlen($suffix)) == $suffix) {
            return substr($str, 0, -strlen($suffix));
        }
        return $str;
    }
1082149
public static function segmentUrl($url = null)
    {
        if (!is_null($url) && !empty($url)) {
            $url = $url;
        } else {
            $url = self::requestInstance()->getRequestUrl();
        }

        return explode('/', trim($url, '/'));
    }
1004014
protected function createUri($url)
	{
		if ($url instanceof Uri)
		{
			return $url;
		}

		// Create full URL if we are only appending variables to it
		if (substr($url, 0, 1) == '&')
		{
			$vars = array();

			if (strpos($url, '&amp;') !== false)
			{
				$url = str_replace('&amp;', '&', $url);
			}

			parse_str($url, $vars);

			$vars = array_merge($this->vars(), $vars);

			foreach ($vars as $key => $var)
			{
				if ($var == '')
				{
					unset($vars[$key]);
				}
			}

			$url = 'index.php?' . urldecode(http_build_query($vars, '', '&'));
		}

		return new Uri($url);
	}
747868
protected function rewriteUrl($url)
    {
        if (empty($this->hosts)) {
            return $url;
        }

        $randKey = array_rand($this->hosts, 1);

        // BC
        if (is_numeric($randKey)) {
            $host = parse_url($url, PHP_URL_SCHEME).'://'.parse_url($url, PHP_URL_HOST);
            $proxyHost = $this->hosts[$randKey];

            return str_replace($host, $proxyHost, $url);
        }

        if (0 === mb_strpos($randKey, 'regexp/')) {
            $regExp = mb_substr($randKey, 6);

            return preg_replace($regExp, $this->hosts[$randKey], $url);
        }

        return str_replace($randKey, $this->hosts[$randKey], $url);
    }
349900
protected static String formatUserUrl(String username) {
        String url = USERS_MAPPING + USER_MAPPING;
        url = url.replaceAll("\\{username.*\\}", username);
        return url;
    }
1107572
static public function uri($url)
    {
        $res = parse_url($url);
        $return['protocol'] = $res['scheme'];
        $return['host'] = $res['host'];
        $return['port'] = $res['port'];
        $return['user'] = $res['user'];
        $return['pass'] = $res['pass'];
        $return['path'] = $res['path'];
        $return['id'] = $res['fragment'];
        parse_str($res['query'], $return['params']);
        return $return;
    }
1181531
public static function swap_protocol( $url ) {
		if ( stristr($url, 'http:') ) {
			return str_replace('http:', 'https:', $url);
		}
		if ( stristr($url, 'https:') ) {
			return str_replace('https:', 'http:', $url);
		}
		return $url;
	}
283127
private function fixUriParts($url)
    {
        $position = Str::strpos($url, '?') ?: Str::strpos($url, '#');

        if ($position === false) {
            return $url;
        }

        return Str::substr($url, 0, $position) . '/' . Str::substr($url, $position);
    }
1054167
protected function applyPrefixAndSuffix($username)
    {
        $prefix = $this->configuration->get('account_prefix');
        $suffix = $this->configuration->get('account_suffix');

        return $prefix.$username.$suffix;
    }
65941
protected function getUuidFromUrl(Url $url)
    {
        $segments = $url->getPathSegments();

        if (count($segments) < 1) {
            throw new Exception('Invalid UUID');
        }

        if (count($segments) < 2) {
            return $segments[0];
        }

        return $segments[count($segments) - 2];
    }
1132688
public static function extractRepositoryNameFromUrl($url) {
		// /path/to/repo.git => repo
		// host.xz:foo/.git => foo
		$directory = rtrim($url, '/');
		if(substr($directory, -5) === '/.git') {
			$directory = substr($directory, 0, -5);
		}
		$directory = basename($directory, '.git');
		if(($pos = strrpos($directory, ':')) !== false) {
			$directory = substr($directory, $pos + 1);
		}
		return $directory;
	}
105457
public function signUrl($url)
    {
        if (strrpos($url, '?') === false) {
            // append ? if one doesn't exist
            $url .= '?';
        }
        return sprintf('%s&policy=%s&signature=%s',
            $url, $this->policy, $this->signature);
    }
378351
public static function url_to_file_system( $url ) {
		$url_parts = parse_url($url);
		$url_parts['path'] = apply_filters('timber/URLHelper/url_to_file_system/path', $url_parts['path']);
		$path = ABSPATH.$url_parts['path'];
		$path = str_replace('//', '/', $path);
		return $path;
	}
988540
static public function rUrl($url)
    {
        $module = null;
        if (strpos($url, 'http') !== 0 && ($pos = strpos($url, ':')) !== false) {    // 1. "x:a/b" module or xUrl
            $module = trim(substr($url, 0, $pos), '/');
            $url   = trim(substr($url, $pos + 1), '/');
        }
        
        if (strpos($url, 'http') === 0) {
            $url = str_replace(static::url($module . ':'), '', $url);
        }
        
        return trim($url, '/');
    }
481562
protected function urlToDsn(Url $url)
    {

        $driver = $url->scheme;
        $db = $url->path ? $url->path : '';
        $port = $url->port;
        $host = $url->host;

        if ($driver == 'sqlite') {
            return $host == 'memory' ? 'sqlite::memory:' : "sqlite:$db";
        }

        $parts = [];

        if ($db) {
            $parts[] = "dbname=" . trim($db, '/');
        }

        if ($host) {
            $parts[] = "host=$host";
        }

        if ($port) {
            $parts[] = "port=$port";
        }

        return "$driver:" . implode(';', $parts);

    }
143787
function _remove_url_suffix()
	{
		if  ($this->getConfig('url_suffix') != "")
		{
			$this->uri_string = preg_replace("|".preg_quote($this->getConfig('url_suffix'))."$|", "", $this->uri_string);
		}
	}