Generate a URL from an array with similar structure as returned from parse_url.

@param array $parts An array in the format produced from parse_url
@return string
342497
public static function buildFromParseUrlParts(array $parts) {
        $url = '';

        $url .= isset($parts['scheme']) ? $parts['scheme'] : 'http';
        $url .= '://';

        if (isset($parts['user'])) {
            $url .= $parts['user'];

            if (isset($parts['pass'])) {
                $url .= ':' . $parts['pass'];
            }

            $url .= '@';
        }

        $url .= isset($parts['host']) ? $parts['host'] : '';
        $url .= isset($parts['port']) ? ':' . $parts['port'] : '';
        $url .= isset($parts['path']) ? $parts['path'] : '';
        $url .= isset($parts['query']) ? '?' . $parts['query'] : '';
        $url .= isset($parts['fragment']) ? '#' . $parts['fragment'] : '';

        return $url;
    }
855181
public static function url($segments, $options = array())
    {
        $request = Router::getInstance()->request;

        $options['X-App-Id'] = Context::getKey()->app_id;
        $options['X-App-Key'] = Context::getKey()->key;

        $segments .= '?' . http_build_query($options);

        return $request->getUrl() . $request->getScriptName() . '/' . $segments;
    }
994422
protected function marshalInstance(array $parts)
    {
        $this->scheme = array_key_exists('scheme', $parts)
            ? $this->marshalScheme($parts['scheme'])
            : ''
        ;

        $this->userInfo = $parts['user'] ?? null;

        if ( array_key_exists('pass', $parts) ) {
            $this->userInfo .= ':'.$parts['pass'];
        }

        $this->host = array_key_exists('host', $parts)
            ? $this->marshalHost($parts['host'])
            : $this->host
        ;

        $this->port = array_key_exists('port', $parts)
            ? $this->marshalPort($parts['port'])
            : null
        ;

        $this->path = array_key_exists('path', $parts)
            ? $this->marshalPath($parts['path'])
            : '/'
        ;

        $this->query = array_key_exists('query', $parts)
            ? $this->marshalQueryAndFragment($parts['query'])
            : null
        ;

        $this->fragment = array_key_exists('fragment', $parts)
            ? $this->marshalQueryAndFragment($parts['fragment'])
            : null
        ;

        if ( empty($this->scheme) && ! array_key_exists('host', $parts) && ! array_key_exists('port', $parts) ) {
            $this->scheme = 'http';
        }

        $this->calibratePort();
    }
1214176
public function generate_adminurl($segments){
		$URL='admin.'.BHOSTNAME.'/';
		if(!empty($segments['branch'])) $URL.=$segments['branch'].'/';
		switch($segments['view']){
			case 'login':
				$URL.='login';
				if(!empty($segments['url'])) $URL.='?redirect='.$segments['url'];
				break;
			case 'logout':
				$URL.='logout';
				break;
			case 'adminusers':				
				$URL.='all/';
				break;
			case 'adminlogs':				
				$URL.='logs/';
				break;
			case 'systeminfo':				
				$URL.='systeminfo.json';
				break;
			case 'adminuserssingle':
				$URL.='user/'.$segments['id'];
				break;
			case 'adminusersgroups':
				$URL.='groups/';
				break;
			case 'adminusersgroup':
				$URL.='groups/'.$segments['id'];
				break;
			case 'adminusersgroupnew':
				$URL.='groups/new';
				break;
			case 'adminusersnew':
				$URL.='new/';
				break;
			case 'langall':
				$URL.='languages/';
				if(!empty($_SERVER['QUERY_STRING'])) $URL.='?'.$_SERVER['QUERY_STRING'];
				break;
			case 'langsave':
				$URL.='languages/save';
				break;
			case 'rubricsall':
				$URL.='rubrics/';
				break;
			case 'rubricssingle':
				$URL.='rubrics/'.$segments['id'];
				break;
			case 'rubricsnew':
				$URL.='rubrics/new';
				break;
			case 'subdomains':
				$URL.='subdomains/';
				break;
			case 'subdomain':
				$URL.='subdomains/'.$segments['subdomain'];
				break;
			case 'subdomainnew':
				$URL.='subdomains/new';
				break;
			case 'newscats':
				$URL.='cats/';
				break;
			case 'newscat':
				$URL.='cats/'.$segments['id'];
				break;
			case 'newscatnew':
				$URL.='cats/new';
				break;
			case 'articles':
				$URL.='articles/';
				if(!empty($_SERVER['QUERY_STRING'])) $URL.='?'.$_SERVER['QUERY_STRING'];
				break;
			case 'article':
				$URL.='articles/'.$segments['id'];
				break;
			case 'articlenew':
				$URL.='articles/new';
				break;
			case 'configuration':
				$URL.='configuration/';
				break;
			case 'softmodules_mainpage':
				$URL.='softmodules/';
				break;
			case 'softmodules_page':
				$URL.='softmodules/page/'.$segments['id'];
				break;
			case 'softmodules_module':
				$URL.='softmodules/modules/'.$segments['id'];
				break;
			case 'softmodules_modulenew':
				$URL.='softmodules/modules/new';
				if(!empty($_SERVER['QUERY_STRING'])) $URL.='?'.$_SERVER['QUERY_STRING'];
				break;
			case 'menu':
				$URL.='menu/';
				break;
			case 'menuitems':
				$URL.='menu/menuitems/'.$segments['id'];
				break;
			case 'menu_ordering_json':
				$URL.='menu/menuitems/ordering.json';
				break;
			case 'menuite_mnew':
				$URL.='menu/menuitem/new';
				break;
			case 'menunew':
				$URL.='menu/new';
				break;
			case 'user':
				$URL.='users/'.$segments['id'];
				break;
			case 'users':
				$URL.='users/';
				if(!empty($_SERVER['QUERY_STRING'])) $URL.='?'.$_SERVER['QUERY_STRING'];
				break;
			}
		return $URL;
		}
357511
public function internalize($url = '')
    {

        //Are we dealing with an array of parts?
        if (is_array($url)) {
            $url = implode('/', $url);
        }

        //@TODO make sure that this url does not have the scheme
        if (preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url))
            return $url;
        //@TODO make sure that this url does not have the host already
        //@TODO make sure we are internalizing a path and nothing else
        //die;
        //Do we have the path info included?
        $sPath = $this->request->getBasePath() . "/";


        if (!empty($url) && $sPath <> "/") {

            $parts = explode("/", $sPath);
            $segments = explode("/", $url);

            //Remove all empty elements
            $segments = array_filter($segments, 'strlen');
            $parts = array_filter($parts, 'strlen');
            //die;
            //This is in case we have a system deep in multiple supdirectories
            array_unshift($parts, null);
            $fragment = implode("/", $parts);

            if (is_array($segments)) {

                array_unshift($segments, null); //Adds the / to the start of the url
                $url = implode("/", $segments);

                //now look for $fragment at the start of $url
                $pos = strpos($url, $fragment);
                if ($pos !== 0 || $pos === FALSE) {
                    $url = $fragment . $url;
                }
            }
        }
        return $url;
    }
106357
protected function buildUrl($parts, $params)
    {
        $url = '';

        if (isset($parts['host'])) {
            if ($this->isRelativeDomain) {
                $url .= '//'.$parts['host'];
            } else {
                $url .= $parts['scheme'].'://'.$parts['host'];
            }

            if (isset($parts['port'])) {
                $url .= ':'.$parts['port'];
            }
        }

        $url .= $parts['path'];

        if (count($params)) {
            $url .= '?'.http_build_query($params);
        }

        return $url;
    }
317272
private static function buildPath($root, array $parts)
    {
        if ($parts === []) {
            return $root === '' ? '.' : $root;
        }

        return $root . implode(DIRECTORY_SEPARATOR, $parts);
    }
1134796
private static function explodePath($parts)
    {
        if (!is_array($parts)) {
            $parts = explode(self::$delimiter, $parts);
        }

        return $parts;
    }
486994
public static function multibyteParseUrl($url)
    {
        $enc_url = preg_replace_callback(
            '%[^:/@?&=#]+%usD',
            function ($matches) {
                return urlencode($matches[0]);
            },
            $url
        );

        $parts = parse_url($enc_url);

        if($parts === false) {
            throw new \InvalidArgumentException('Malformed URL: ' . $url);
        }

        foreach($parts as $name => $value) {
            $parts[$name] = urldecode($value);
        }

        return $parts;
    }
763507
function joinUrlParts(...parts: Array<string>): string {
  let result = '';
  parts.forEach((part, index) => {
    if (index !== 0 && !/\/$/.test(result) && !/^\//.test(part)) {
      result += '/';
    }
    result += part;
  });
  return result;
}
140139
protected function processParts(array $parts)
    {
        $strValue = '';
        $filtered = $this->filterIgnoredSpaces($parts);
        foreach ($filtered as $part) {
            $strValue .= $part->getValue();
        }
        return [$this->partFactory->newLiteralPart($strValue)];
    }
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;
	}
1369819
protected function getNestedResourceUri(array $segments)
	{
		$me = $this;

		// We will spin through the segments and create a place-holder for each of the
		// resource segments, as well as the resource itself. Then we should get an
		// entire string for the resource URI that contains all nested resources.
		return implode('/', array_map(function($s) use ($me)
		{
			return $s.'/{'.$me->getResourceWildcard($s).'}';

		}, $segments));
	}
1108532
protected function makeUrl( array$params ):string
	{
		$url= $this->url;

		foreach( $params['path']??[] as $key=>$value )
		{
			$url= str_replace( "{{$key}}", $value, $url );
		}

		if( $params['query']??null )
		{
			$url.= '?'.http_build_query( $params['query'] );
		}

		return $url;
	}
326889
protected function buildUri(array $parts)
    {
        $uri = 
            ($parts['scheme'] ? "{$parts['scheme']}:" : '') . 
            ($parts['user'] || $parts['host'] ? '//' : '') . 
            ($parts['user'] ? "{$parts['user']}" : '') . 
            ($parts['user'] && $parts['pass'] ? ":{$parts['pass']}" : '') . 
            ($parts['user'] ? '@' : '') . 
            ($parts['host'] ? "{$parts['host']}" : '') . 
            ($parts['port'] ? ":{$parts['port']}" : '');
            
        $uri .=
            ($uri && $parts['path'] && $parts['path'][0] !== '/' ? '/' : '') .
            ($parts['path'] ? "{$parts['path']}" : '') . 
            ($parts['query'] ? "?{$parts['query']}" : '') . 
            ($parts['fragment'] ? "#{$parts['fragment']}" : '');
            
        return $uri;
    }
552741
protected function buildCommentsPath(string ...$parts)
    {
        return static::buildPath('repositories', $this->username, $this->repo, 'pullrequests', $this->pr, 'comments', ...$parts);
    }
745651
protected function buildVotingPath(string ...$parts)
    {
        return static::buildPath('repositories', $this->username, $this->repo, 'issues', $this->issue, 'vote', ...$parts);
    }