Rebuilt the URL with all known parts
@return string
@throws RuntimeException
495754
public function toString()
    {
        $url = $this->scheme.':';
        if (trim($this->host) != '') {
            $url .= '//';
            if (trim($this->user) != '') {
                $url .= $this->user.((trim($this->pass) != '')?':'.$this->pass:'').'@';
            }
            $url .= $this->host;

            if (trim($this->port) != '') {
                $url .= ':'.$this->port;
            }
        }

        $url .= (trim($this->path) != '')?$this->path:'';
        $url .= (trim($this->query) != '')?'?'.$this->query:'';
        $url .= (trim($this->fragment) != '')?'#'.$this->fragment:'';

        if (!self::isValid($url)) {
            throw new RuntimeException('Built URL is not a valid one: '.$url);
        }

        return $url;
    }
1092614
public function process()
    {
        $this->_cleanFilesStack();
        $this->init();

        if (empty($this->destination_file) && false===$this->direct_output) {
            $this->guessDestinationFilename();
        }

        if (!method_exists($this->__adapter, $this->__adapter_action)) {
            throw new \RuntimeException(
                sprintf('[Compressor] Action "%s" doesn\'t exist in "%s" adapter!', $this->__adapter_action, get_class($this->__adapter))
            );
        }

        if (false===$this->direct_output) {
            if (!$this->mustRefresh()) {
                $this->output = file_get_contents($this->getDestinationRealPath());
                return $this;
            }
        }

        $this->prepare();
        $stack = $this->getContents();
        $contents = array();
        foreach ($stack as $_name=>$_content) {
            $contents[] = '';
            $contents[] = $this->__adapter->buildComment($_name);
            $contents[] = $this->__adapter->{$this->__adapter_action}($_content);
        }
        if (!empty($this->raw_header)) {
            $this->output = $this->raw_header."\n";
        }
        $this->output .= implode("\n", $contents);

        if (!empty($this->output) && false===$this->direct_output) {
            $this->_writeDestinationFile();
        }
        return strlen($this->output);
    }
494028
public function getRawContent()
    {
        if ($this->size == 0) {
            return '';
        }

        if ($this->encoding === 'base64') {
            $raw = base64_decode($this->content, true);
            if ($raw === false) {
                throw new \RuntimeException('Failed to decode content');
            }

            return $raw;
        }

        throw new \RuntimeException('Unrecognised blob encoding: ' . $this->encoding);
    }
618463
public function getContents()
    {
        if (!is_resource($this->stream)) {
            throw new \RuntimeException('Cannot read from empty resource stream');
        }

        $this->rewind();

        $contents = stream_get_contents($this->stream);

        if ($contents === false) {
            throw new \RuntimeException('Unable to read stream contents');
        }

        return $contents;
    }
916859
public function buildUrl()
    {

        if (isset($this->otherOptions['urlProcessRegEx'])
            && !empty($this->otherOptions['urlProcessRegEx'])
        ) {
            unset($this->otherOptions['urlProcessPattern']);
        }

        if (isset($this->otherOptions['urlCrawlRegEx'])
            && !empty($this->otherOptions['urlCrawlRegEx'])
        ) {
            unset($this->otherOptions['urlCrawlPattern']);
        }


        // Add token
        $url = 'token=' . $this->diffbot->getToken();

        if ($this->getName()) {
            // Add name
            $url .= '&name=' . $this->getName();

            // Add seeds
            if (!empty($this->seeds)) {
                $url .= '&seeds=' . implode('%20', array_map(function ($item) {
                        return urlencode($item);
                    }, $this->seeds));
            }

            // Add other options
            if (!empty($this->otherOptions)) {
                foreach ($this->otherOptions as $option => $value) {
                    $url .= '&' . $option . '=' . $value;
                }
            }

            // Add API link
            $url .= '&apiUrl=' . $this->getApiString();
        }

        return $url;
    }
813681
public static function assembleUrl ($parts) {
    $url = '';
    if (isset($parts['scheme'])) {
      $url .= "{$parts['scheme']}:";
    }
    $url .= '//';
    if (isset($parts['user'])) {
      $url .= $parts['user'];
      if (isset($parts['password'])) {
        $url .= ":{$parts['password']}";
      }
      $url .= '@';
    }
    if (isset($parts['host'])) {
      $url .= $parts['host'];
    }
    if (isset($parts['port'])) {
      $url .= ":{$parts['port']}";
    }
    if (isset($parts['path'])) {
      $url .= $parts['path'];
    }
    if (isset($parts['query'])) {
      $url .= "?{$parts['query']}";
    }
    if (isset($parts['fragment'])) {
      $url .= "#{$parts['fragment']}";
    }
    return $url;
  }
702783
public static function getCurrentUrlNoParam(){
		$url = self::getCurrentUrl();
		if(strstr($url,"#")){
			$url = substr($url,0,strpos($url,"#"));
		}
		
		if(strstr($url,"?")){
			$url = substr($url,0,strpos($url,"?"));
		}
		return $url;
		
	}
855199
public function getBaseRouteName()
    {
        if (null !== $this->cachedBaseRouteName) {
            return $this->cachedBaseRouteName;
        }

        if ($this->isChild()) { // the admin class is a child, prefix it with the parent route name
            $baseRouteName = $this->baseRouteName;
            if (!$this->baseRouteName) {
                preg_match(self::CLASS_REGEX, $this->class, $matches);

                if (!$matches) {
                    throw new \RuntimeException(sprintf('Cannot automatically determine base route name, please define a default `baseRouteName` value for the admin class `%s`', \get_class($this)));
                }
                $baseRouteName = $this->urlize($matches[5]);
            }

            $this->cachedBaseRouteName = sprintf(
                '%s_%s',
                $this->getParent()->getBaseRouteName(),
                $baseRouteName
            );
        } elseif ($this->baseRouteName) {
            $this->cachedBaseRouteName = $this->baseRouteName;
        } else {
            preg_match(self::CLASS_REGEX, $this->class, $matches);

            if (!$matches) {
                throw new \RuntimeException(sprintf('Cannot automatically determine base route name, please define a default `baseRouteName` value for the admin class `%s`', \get_class($this)));
            }

            $this->cachedBaseRouteName = sprintf('admin_%s%s_%s',
                empty($matches[1]) ? '' : $this->urlize($matches[1]).'_',
                $this->urlize($matches[3]),
                $this->urlize($matches[5])
            );
        }

        return $this->cachedBaseRouteName;
    }
141251
public function getContents()
    {
        if (!$this->isReadable()) {
            throw new \RuntimeException("Stream isn't readable");
        }
        
        $contents = '';
        
        while (!$this->eof()) {
            $contents .= $this->read(512000);
        }
        
        return $contents;
    }
537296
protected function buildUrl()
    {
        $url = '';

        if (isset($this->info['content'])) {
            return 'data:'.$this->info['content'];
        }

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

        $user = isset($this->info['user']) ? $this->info['user'] : '';
        $pass = isset($this->info['pass']) ? ':'.$this->info['pass'] : '';
        if ($user || $pass) {
            $url .= $user.$pass.'@';
        }

        if (isset($this->info['host'])) {
            $url .= $this->info['host'];
        }

        if (isset($this->info['port'])) {
            $url .= ':'.$this->info['port'];
        }

        $url .= $this->getPath();

        if (!empty($this->info['query'])) {
            $url .= '?'.rtrim(http_build_query($this->info['query']), '=');
        }
        if (isset($this->info['fragment'])) {
            $url .= '#'.$this->info['fragment'];
        }

        return $url;
    }
211114
private function compileUrl()
    {
        if (false === empty($this->parentParentId)) {
            $parentData = self::find()
                ->select(['slug', 'url'])
                ->where(['model_id' => $this->parentParentId, 'language_id' => $this->language_id])
                ->asArray(true)
                ->one();
            $parentSlug = empty($parentData['url'])
                ? (empty($parentData['slug']) ? '' : trim($parentData['slug'], '/'))
                : trim($parentData['url'], '/');
            $url = empty($parentSlug)
                ? trim($this->slug, '/')
                : $parentSlug . '/' . trim($this->slug, '/');
        } else {
            $url = trim($this->slug, '/');
        }
        return $url;
    }
1174852
public function generate()
    {
        if (!isset($_SERVER['REQUEST_URI'])) {
            throw new RuntimeException("Can't auto-detect current page identity");
        }

        $port = ($_SERVER['SERVER_PORT'] == '80') ? '' : (':'.$_SERVER['SERVER_PORT']);
        $scheme = stripos($_SERVER['SERVER_PROTOCOL'], 'https') === 0 ? 'https' : 'http';

        return md5($scheme . '://'.$_SERVER['HTTP_HOST']. $port . $_SERVER['REQUEST_URI']);
    }
1155937
public function getAbsolute(){
		if( empty( $this->parts->scheme ) )
			throw new RuntimeException( 'HTTP scheme not set' );
		if( empty( $this->parts->host ) )
			throw new RuntimeException( 'HTTP host not set' );
		$buffer	= array();
		if( $this->parts->scheme )
			$buffer[]	= $this->parts->scheme.'://';
		if( $this->parts->user ){
			$buffer[]	= $this->parts->user;
			if( $this->parts->pass )
				$buffer[]	= ':'.$this->parts->pass;
			$buffer[]	= '@';
		}
		if( $this->parts->host )
			$buffer[]	= $this->parts->host;
		if( $this->parts->port )
			$buffer[]	= ':'.$this->parts->port;
		if( $this->parts->path )
			$buffer[]	= $this->parts->path;
		if( $this->parts->query )
			$buffer[]	= '?'.$this->parts->query;
		if( $this->parts->fragment )
			$buffer[]	= '#'.$this->parts->fragment;
		return join( '', $buffer );
	}
649634
protected function initUrlSegments () {
		$this->portDefined = FALSE;
		$this->port = '';
		$this->path = '';
		$this->query = '';
		$this->fragment = '';

		$uri = $this->GetScheme() . '//'
			. $this->globalServer['HTTP_HOST'];
		if (isset($this->globalServer['UNENCODED_URL'])) {
			$uri .= rawurldecode($this->globalServer['UNENCODED_URL']);
		} else if (isset($this->globalServer['UNENCODED_URL'])) {
			$uri .= rawurldecode($this->globalServer['UNENCODED_URL']);
		} else {
			$uri .= rawurldecode($this->globalServer['REQUEST_URI']);
		}

		$firstColonPos = mb_strpos($uri, ':');
		if ($firstColonPos !== FALSE) 
			$uri = mb_substr($uri, $firstColonPos + 1);
		
		if (mb_substr($uri, 0, 2) === '//') {
			$nextSlashPos = mb_strpos($uri, '/', 2);
			if ($nextSlashPos !== FALSE) {
				$authority = mb_substr($uri, 2, $nextSlashPos - 2);
				$uri = mb_substr($uri, $nextSlashPos);
				$colonsCount = mb_substr_count($authority, ':');
				if ($colonsCount === 1) {
					$colonPos = mb_strpos($authority, ':');
					$this->port = mb_substr($authority, $colonPos + 1);
					if ($this->port !== '') 
						$this->portDefined = TRUE;
				}
			} else {
				return;
			}
		}

		$basePath = $this->GetBasePath();
		$uri = mb_substr($uri, mb_strlen($basePath));
		
		$questionMarkPos = mb_strpos($uri, '?');
		$hashPos = mb_strpos($uri, '#');
		$questionMarkContained = $questionMarkPos !== FALSE;
		$hashContained = $hashPos !== FALSE;
		if (!$questionMarkContained && !$hashContained) {
			// path, no query, no hash
			$this->path = $uri;
		} else if ($questionMarkContained && !$hashContained) {
			// path, query and no hash
			$this->path = mb_substr($uri, 0, $questionMarkPos);
			$this->query = trim(mb_substr($uri, $questionMarkPos + 1), '&');
		} else if (!$questionMarkContained && $hashContained) {
			// path, no query and hash
			$this->path = mb_substr($uri, 0, $hashPos);
			$this->fragment = mb_substr($uri, $hashPos + 1);
		} else if ($questionMarkContained && $hashContained && $questionMarkPos < $hashPos) {
			// path, query and hash
			$this->path = mb_substr($uri, 0, $questionMarkPos);
			$this->query = trim(mb_substr($uri, $questionMarkPos + 1, $questionMarkPos + 1 - $hashPos), '&');
			$this->fragment = mb_substr($uri, $hashPos + 1);
		} else {
			// path, no query and hash containing question mark
			$this->path = mb_substr($uri, 0, $questionMarkPos);
			$this->fragment = mb_substr($uri, $hashPos + 1);
		}
	}
1199746
private function generateNewPart(): void
    {
        if ($this->buffer) {
            $this->closeSitemap();
        }

        $this->bufferUrlCount = 0;
        $this->bufferSize = 0;
        ++$this->bufferPart;

        if (!is_writable($this->folder)) {
            throw new \RuntimeException(sprintf('Unable to write to folder: %s', $this->folder));
        }

        $filename = sprintf($this->pattern, $this->bufferPart);

        $this->buffer = fopen($this->folder.'/'.$filename, 'w');

        $this->bufferSize += fwrite($this->buffer, '<?xml version="1.0" encoding="UTF-8"?>'."\n".'<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"'.$this->getHeaderByFlag().'>'."\n");
    }
730618
public function getNestedController() {
		$request = $this->request;
		$segment = $request->param('URLSegment');
		$site    = Multisites::inst()->getCurrentSiteId();

		if(!$site) {
			return $this->httpError(404);
		}

		$page = SiteTree::get()->filter(array(
			'ParentID'   => $site,
			'URLSegment' => rawurlencode($segment)
		));
		$page = $page->first();

		if(!$page) {
			// Check to see if linkmapping module is installed and if so, if there a map for this request.
			if(class_exists('LinkMapping')){
				$queryString = '?';
				if ($request->requestVars()){
					foreach($request->requestVars() as  $key => $value) {
						if($key !='url'){$queryString .=$key.'='.$value.'&';}
					}
					$queryString =  rtrim($queryString,'&');
				}
				$link = ($queryString != '?' ? $request->getURL().$queryString : $request->getURL());
				$link = trim(Director::makeRelative($link));

				$map  = LinkMapping::get()->filter('MappedLink', $link)->first();

				if ($map) {
					$this->response = new HTTPResponse();
					$this->response->redirect($map->getLink(), 301);
					return $this->response;
				}	
			}
	
			// use OldPageRedirector if it exists, to find old page
			if(class_exists(OldPageRedirector::class)){
				if($redirect = OldPageRedirector::find_old_page(array($segment), Multisites::inst()->getCurrentSite())){
					$redirect = SiteTree::get_by_link($redirect);
				}
			}else{
				$redirect = self::find_old_page($segment, $site);			
			}			

			if($redirect) {
				$getVars = $request->getVars();
				//remove the url var as it confuses the routing
				unset($getVars['url']);
				
				$url = Controller::join_links(
						$redirect->Link(
							Controller::join_links(
								$request->param('Action'),
								$request->param('ID'),
								$request->param('OtherID')
							)
						)
					);
				
				if(!empty($getVars)){
					$url .= '?' . http_build_query($getVars);
				}
				
				$this->response->redirect($url, 301);

				return $this->response;
			}

			return $this->httpError(404);
		}


		return self::controller_for($page, $request->param('Action'));
	}
690275
protected function readAll()
    {
        $level = error_reporting(0);
        $url = (string)$this->url();
        $body = file_get_contents($url, 0, $this->streamContext());

        error_reporting($level);

        if ($body === false) {
            $error = error_get_last();
            $message = isset($error['message']) && $error['message'] ? $error['message'] : "Cannot read from $url.";
            throw new RuntimeException($message);
        }



        if (isset($http_response_header)) {
            $header = implode("\r\n", $http_response_header);
            return "$header\r\n\r\n$body";
        }

        return $body;
    }