creates a new instance of the current exact uri and changes the fragment to
the provided fragment string.

This method will NOT remove preceding hash tags.

@param string $fragment
@return UriInterface
329035
public function withFragment(string $fragment): UriInterface
    {
        $instance = clone $this;
        $instance->fragment = $this->marshalQueryAndFragment($fragment);

        return $instance;
    }
735631
protected function createUriPointerMap(UriInterface $uri)
    {
        $uri = clone $uri;
        $uri->normalize();
        $map = array(array($uri->toString(), array()));

        $fragmentPointer = $this->pointerFactory()->createFromUri($uri);
        if ($fragmentPointer->hasAtoms()) {
            $atoms = array();
            $fragmentlessUri = clone $uri;
            $fragmentlessUri->setFragment(null);

            while ($fragmentPointer->hasAtoms()) {
                array_unshift($atoms, $fragmentPointer->lastAtom());
                $fragmentPointer = $fragmentPointer->parent();

                $uri = clone $fragmentlessUri;
                $uri->setFragment($fragmentPointer->string());
                $uri->normalize();

                array_unshift($map, array($uri->toString(), $atoms));
            }
        }

        return $map;
    }
161335
function makeUri($uri) {
      $a = parse_url($uri);

      if ( (isset($a['scheme'])) && (isset($a['host'])) ) {
        $this->url = $a;
      } else {
        unset($this->url['query']);
        unset($this->url['fragment']);
        $this->url = array_merge($this->url, $a);
      }

      if ($this->useProxy) {
        $requesturi = 'http://' . $this->url['host'] . (empty($this->url['port']) ? '' : ':' . $this->url['port']) . $this->url['path'] . (empty($this->url['query']) ? '' : '?' . $this->url['query']);
      } else {
        $requesturi = $this->url['path'] . (empty($this->url['query']) ? '' : '?' . $this->url['query']);
      }

      return $requesturi;
    }
284009
private static function createUriString($scheme, $authority, $path, $query, $fragment)
    {
        $uri = '';

        if (!empty($scheme)) {
            $uri .= $scheme . '://';
        }

        if (!empty($authority)) {
            $uri .= $authority;
        }

        if ($path != null) {
            $uri .= $path;
        }

        if ($query != null) {
            $uri .= '?' . $query;
        }

        if ($fragment != null) {
            $uri .= '#' . $fragment;
        }

        return $uri;
    }
128446
public function withQuery(string $query): UriInterface
    {
        $query = $this->marshalQueryAndFragment($query);

        if ( $this->query === $query ) {
            return $this;
        }

        $instance = clone $this;
        $instance->query = $query;

        return $instance;
    }
674597
protected static function normalizeFragment(?string $fragment): ?string
    {
        if ($fragment === null) {
            return null;
        }

        if (!static::isValidFragment($fragment)) {
            $message = sprintf('Invalid URI fragment: %s', $fragment);
            throw new DomainException($message);
        }

        return static::encodeFragment(static::decode($fragment, static::UNRESERVED_SET));
    }
211265
public static function buildUrl(array $parts)
    {
        $url = $scheme = '';

        if (!empty($parts['scheme'])) {
            $scheme = $parts['scheme'];
            $url .= $scheme . ':';
        }

        if (!empty($parts['host'])) {
            $url .= '//';
            if (isset($parts['user'])) {
                $url .= $parts['user'];
                if (isset($parts['pass'])) {
                    $url .= ':' . $parts['pass'];
                }
                $url .=  '@';
            }

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

            // Only include the port if it is not the default port of the scheme
            if (isset($parts['port']) &&
                (!isset(self::$defaultPorts[$scheme]) ||
                 $parts['port'] != self::$defaultPorts[$scheme])
            ) {
                $url .= ':' . $parts['port'];
            }
        }

        // Add the path component if present
        if (isset($parts['path']) && strlen($parts['path'])) {
            // Always ensure that the path begins with '/' if set and something
            // is before the path
            if (!empty($parts['host']) && $parts['path'][0] != '/') {
                $url .= '/';
            }
            $url .= $parts['path'];
        }

        // Add the query string if present
        if (isset($parts['query'])) {
            $queryStr = (string) $parts['query'];
            if ($queryStr || $queryStr === '0') {
                $url .= '?' . $queryStr;
            }
        }

        // Ensure that # is only added to the url if fragment contains anything.
        if (isset($parts['fragment'])) {
            $url .= '#' . $parts['fragment'];
        }

        return $url;
    }
575642
public static function createFromUnixPath(string $uri = ''): self
    {
        $uri = implode('/', array_map('rawurlencode', explode('/', $uri)));
        if ('/' !== ($uri[0] ?? '')) {
            return Uri::createFromComponents(['path' => $uri]);
        }

        return Uri::createFromComponents(['path' => $uri, 'scheme' => 'file', 'host' => '']);
    }
1346721
public static UriTemplate append(UriTemplate uriTemplate, String fragment) {
    return new UriTemplate(uriTemplate.toString() + fragment, uriTemplate.encodeSlash(),
        uriTemplate.getCharset());
  }
326077
public static DocLink fragment(String fragment) {
        return new DocLink((String) null, (String) null, fragment);
    }
1291782
public function getHref()
    {
        $uri = $this->getUri();
        
        $fragment = $this->getFragment();       
        if (null !== $fragment) {
            if ('#' == substr($uri, -1)) {
                return $uri . $fragment;
            } else {                
                return $uri . '#' . $fragment;
            }
        }
        
        return $uri;
    }
106407
public function assertFragmentIs($fragment)
    {
        $pattern = preg_quote($fragment, '/');

        $actualFragment = (string) parse_url($this->driver->executeScript('return window.location.href;'), PHP_URL_FRAGMENT);

        PHPUnit::assertRegExp(
            '/^'.str_replace('\*', '.*', $pattern).'$/u', $actualFragment,
            "Actual fragment [{$actualFragment}] does not equal expected fragment [{$fragment}]."
        );

        return $this;
    }
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;
    }
1296733
public static function fromParts(array $parts): UriInterface
    {
        $uri = new self();
        $uri->applyParts($parts);
        $uri->validateState();

        return $uri;
    }
608358
public function url($default, $query = null, $fragment = null) {
		$url_query = (stristr($default, '?'))?'&':'?';

		if (is_array($query)) {
			$itter = 0;
			foreach ($query as $key => $value) { if ($itter == array_search( $key, $query )) {
				$itter++;
				$url_query .= $key.'='.$value;
			} else {
				$url_query .= '&'.$key.'='.$value;
			} }
		}

		if (isset($url_query) && strlen($url_query) > 1) {
			$url_query = (stristr(urldecode($default), substr($url_query, 1)))?'':$url_query;
		}

		$url = $default.((strlen( $url_query ) > 1)?$url_query:'').(($fragment)?'#'.$fragment:'');

		return $url;
	}
83000
public static function createFromParse(array $parts)
    {
        $uri = new static();
        if (isset($parts['schema'])) {
            $uri->scheme = UriFilter::scheme($parts['schema']);
        }
        if (isset($parts['host'])) {
            $uri->host = UriFilter::host($parts['host']);
        }
        if (isset($parts['port'])) {
            $uri->port = UriFilter::port($parts['port']);
        }
        if (isset($parts['path'])) {
            $uri->path = UriFilter::path($parts['path']);
        }
        if (isset($parts['query'])) {
            $uri->query = UriFilter::body($parts['query']);
        }
        if (isset($parts['fragment'])) {
            $uri->fragment = UriFilter::body($parts['fragment']);
        }
        if (isset($parts['user'])) {
            $uri->userInfo = $parts['user'];
        }
        if (isset($parts['pass'])) {
            $uri->userInfo .= ':' . $parts['pass'];
        }
        $uri->validate();
        return $uri;
    }
1123214
public function withHost(string $host): UriInterface
    {
        $instance = clone $this;
        $instance->host = $this->marshalHost($host);

        return $instance;
    }