Build a URL path from the given parts.

@param string[] $parts

@throws \Bitbucket\Exception\InvalidArgumentException

@return string
7812
protected static function buildPath(string ...$parts)
    {
        $parts = array_map(function (string $part) {
            if (!$part) {
                throw new InvalidArgumentException('Missing required parameter.');
            }

            return self::urlEncode($part);
        }, $parts);

        return implode('/', $parts);
    }
54996
public static function buildUrl(array $parts)
    {
        $scheme = isset($parts['scheme']) ? $parts['scheme'] . '://' : '';
        $host = isset($parts['host']) ? $parts['host'] : '';
        $port = isset($parts['port']) ? ':' . $parts['port'] : '';
        $user = isset($parts['user']) ? $parts['user'] : '';
        $pass = isset($parts['pass']) ? ':' . $parts['pass'] : '';
        $pass = ($user || $pass) ? "$pass@" : '';
        $path = isset($parts['path']) ? $parts['path'] : '';
        $query = isset($parts['query']) ? '?' . $parts['query'] : '';
        $fragment = isset($parts['fragment']) ? '#' . $parts['fragment'] : '';
        return $scheme . $user . $pass . $host . $port . $path . $query . $fragment;
    }
655206
protected function buildStatusesPath(string ...$parts)
    {
        return static::buildPath('repositories', $this->username, $this->repo, 'commit', $this->commit, 'statuses', ...$parts);
    }
200283
static function buildUrl($parts)
    {
        $parts = new ArrayObject($parts);

        ###################
        ### PARSE PARTS ###
        ###################

        // scheme
        $scheme = $parts->key('scheme', '', true);

        // host
        $host = $parts->key('host', '', true);

        // port
        $port = $parts->key('port', '', true);

        // path
        $path = $parts->key('path', '', true);

        // parse query string
        $query = '';
        if($parts->keyExists('query')) {
            if(self::isString($parts->key('query'))) {
                parse_str($parts->key('query'), $queryData);
            } else {
                $queryData = $parts->key('query');
            }

            if(self::isArray($queryData)) {
                $query = $queryData;
            }
        }


        ###################
        ### BUILD URL   ###
        ###################
        $url = '';

        // scheme
        if($scheme && $scheme != '') {
            $url .= $scheme . '://';
        }

        // host
        if($host && $host != '') {
            $url .= $host;
        }

        // port
        if($port != '') {
            $url .= ':' . $port;
        }

        // path
        if($path != '') {
            $url .= $path;
        }

        // query
        if(self::isArray($query)) {
            $query = http_build_query($query);
            if($query != "") {
                $url .= '?' . $query;
            }
        }

        try {
            return new UrlObject($url);
        } catch (\Exception $e) {
            throw new UrlObjectException($e->getMessage());
        }
    }
696346
final protected function URLToString(array $components = array(
		'scheme',
		'user',
		'pass',
		'host',
		'port',
		'path',
		'query',
		'fragment'
	))
	{
		$url = '';
		$query = "{$this->query}";
		if (in_array('scheme', $components)) {
			if (is_string($this->_url_data['scheme'])) {
				$url .= rtrim($this->_url_data['scheme'], ':/') . '://';
			} else {
				$url .= 'http://';
			}
		}

		if (@is_string($this->_url_data['user']) and in_array('user', $components)) {
			$url .= urlencode($this->_url_data['user']);
			if (@is_string($this->_url_data['pass']) and in_array('pass', $components)) {
				$url .= ':' . urlencode($this->_url_data['pass']);
			}
			$url .= '@';
		}

		if (in_array('host', $components)) {
			if (@is_string($this->_url_data['host'])) {
				$url .= $this->_url_data['host'];
			} else {
				$url .= 'localhost';
			}
		}
		if (
			is_int($this->_url_data['port'])
			and ! $this->isDefaultPort($this->_url_data['scheme'], $this->_url_data['port'])
		) {
			$url .= ":{$this->_url_data['port']}";
		}
		if (in_array('path', $components)) {
			if (@is_string($this->_url_data['path'])) {
				$url .= '/' . ltrim($this->_url_data['path'], '/');
			} else {
				$url .= '/';
			}
		}

		if(
			strlen($query) !== 0 and in_array('query', $components)
		) {
			$url .= "?$query";
		}
		if (@is_string($this->_url_data['fragment']) and in_array('fragment', $components)) {
			$url .= '#' . ltrim($this->_url_data['fragment'], '#');
		}
		return $url;
	}
456660
static public function buildUrl($path, $params=null)
	{
	    $parts = explode('?', $path, 2);
	    $pathParams = isset($parts[1]) ? static::parseQuery($parts[1]) : [];
	    if (is_string($params)) {
	        $params = static::parseQuery($params);
	    }
	    if ($params) {
	        $pathParams = array_merge($pathParams, $params);
	    }
	    
	    return $parts[0] . ($pathParams ? '?' . http_build_query($pathParams) : '');
	}
1100704
public static String buildPath(String first, String... parts) {
        StringBuilder result = new StringBuilder(first);

        for (String part : parts) {
            if (result.length() == 0) {
                if (part.startsWith("/")) {
                    result.append(part.substring(1));
                } else {
                    result.append(part);
                }
            } else {
                if (result.toString().endsWith("/") && part.startsWith("/")) {
                    result.append(part.substring(1));
                } else if (!result.toString().endsWith("/") && !part.startsWith("/") && !part.isEmpty()) {
                    result.append("/").append(part);
                } else {
                    result.append(part);
                }
            }
        }

        return result.toString();
    }
114511
private function applyParts(array $parts)
    {
        $this->scheme = isset($parts['scheme'])
            ? $this->filterScheme($parts['scheme'])
            : '';
        $this->userInfo = isset($parts['user']) ? $parts['user'] : '';
        $this->host = isset($parts['host']) ? $parts['host'] : '';
        $this->port = !empty($parts['port'])
            ? $this->filterPort($this->scheme, $this->host, $parts['port'])
            : null;
        $this->path = isset($parts['path'])
            ? $this->filterPath($parts['path'])
            : '';
        $this->query = isset($parts['query'])
            ? $this->filterQueryAndFragment($parts['query'])
            : '';
        $this->fragment = isset($parts['fragment'])
            ? $this->filterQueryAndFragment($parts['fragment'])
            : '';
        if (isset($parts['pass'])) {
            $this->userInfo .= ':' . $parts['pass'];
        }
    }
453795
protected function processParts(array $parts)
    {
        $combined = new ArrayObject();
        $splitParts = new ArrayObject();
        $strCat = '';
        $strName = '';
        $parts[] = $this->partFactory->newToken(';');
        foreach ($parts as $part) {
            $pValue = $part->getValue();
            if ($part instanceof Token && $this->processTokenPart($pValue, $combined, $splitParts, $strName, $strCat)) {
                continue;
            }
            $strCat .= $pValue;
        }
        return $this->finalizeParameterParts($combined);
    }
953297
public static function pathSub($path, $part, $separator = DIRECTORY_SEPARATOR)
    {
        if (empty($path)) {
            throw new ArgumentNullException("path");
        }

        if (empty($part)) {
            throw new ArgumentNullException("part");
        }

        $pattern = '@[/\\\\]+@';
        $path = preg_replace($pattern, DIRECTORY_SEPARATOR, $path);
        $part = preg_replace($pattern, DIRECTORY_SEPARATOR, $part.DIRECTORY_SEPARATOR);
        $part = preg_quote($part, '@');
        $result = preg_replace('@^'.$part.'@', DIRECTORY_SEPARATOR, $path);
        if ($separator != DIRECTORY_SEPARATOR) {
            $result = str_replace(DIRECTORY_SEPARATOR, $separator, $result);
        }

        return $result;
    }
609594
public function getUrl($path, array $params = [])
    {
        $parts = parse_url($this->baseUrl.'/'.trim($path, '/'));

        if ($parts === false) {
            throw new InvalidArgumentException('Not a valid path.');
        }

        $parts['path'] = '/'.trim($parts['path'], '/');

        if ($this->signature) {
            $params = $this->signature->addSignature($parts['path'], $params);
        }

        return $this->buildUrl($parts, $params);
    }
344392
protected function buildWatchingPath(string ...$parts)
    {
        return static::buildPath('repositories', $this->username, $this->repo, 'issues', $this->issue, 'watch', ...$parts);
    }
428488
protected function buildApprovalPath(string ...$parts)
    {
        return static::buildPath('repositories', $this->username, $this->repo, 'pullrequests', $this->pr, 'approve', ...$parts);
    }
1091005
public function fromArray(array $parts)
	{	//	runs parameters through __set()
		$this->scheme	=	$parts['scheme']	??	null;
		$this->user		=	$parts['user']		??	null;
		$this->pass		=	$parts['pass']		??	null;
		$this->host		=	$parts['host']		??	null;
		$this->port		=	$parts['port']		??	null;
		$this->path		=	$parts['path']		??	null;
		$this->query	=	$parts['query']		??	null;
		$this->fragment	=	$parts['fragment']	??	null;
	}
853743
private function escapePathPart($part)
    {
        return preg_match(self::UNESCAPED_FIELD_NAME, $part)
            ? $part
            : '`' . str_replace('`', '\\`', str_replace('\\', '\\\\', $part)) . '`';
    }
251880
protected function buildAttachmentsPath(string ...$parts)
    {
        return static::buildPath('repositories', $this->username, $this->repo, 'issues', $this->issue, 'attachments', ...$parts);
    }
440345
public function getUrl($parts = self::FULL)
    {
        $url = '';

        //Add the scheme
        if (($parts & self::SCHEME) && !empty($this->scheme)) {
            $url .=  urlencode($this->scheme).'://';
        }

        //Add the username and password
        if (($parts & self::USER) && !empty($this->user)) {
            $url .= urlencode($this->user);
            if (($parts & self::PASS) && !empty($this->pass)) {
                $url .= ':' . urlencode($this->pass);
            }

            $url .= '@';
        }

        // Add the host and port, if any.
        if (($parts & self::HOST) && !empty($this->host)) {
            $url .=  urlencode($this->host);

            if (($parts & self::PORT) && !empty($this->port)) {
                $url .=  ':' . (int) $this->port;
            }
        }

        // Add the rest of the url. we use trim() instead of empty() on string
        // elements to allow for string-zero values.
        if (($parts & self::PATH) && !empty($this->path)) {
            $url .= $this->_pathEncode($this->path);
            if (($parts & self::FORMAT) && trim($this->format) !== '') {
                $url .= '.' . urlencode($this->format);
            }
        }

        $query = $this->getQuery();
        
        if (($parts & self::QUERY) && !empty($query)) {
            $url .= '?' . $this->getQuery();
        }

        if (($parts & self::FRAGMENT) && trim($this->fragment) !== '') {
            $url .=  '#' . urlencode($this->fragment);
        }

        return $url;
    }