public function withUri(UriInterface $uri, $preserveHost = false)
    {
        $new = clone $this;
        $new->uri = $uri;

        if ($preserveHost && $this->hasHeader('Host')) {
            return $new;
        }

        $host = $uri->getHost();
        if (!$host) {
            return $new;
        }
        if ($uri->getPort()) {
            $host .= ':' . $uri->getPort();
        }
        $new->_environment['HTTP_HOST'] = $host;

        return $new;
    }
public function withUri(UriInterface $uri, $preserveHost = false)
    {
        $new = clone $this;
        $new->uri = $uri;

        if ($preserveHost && $this->hasHeader('Host')) {
            return $new;
        }

        $host = $uri->getHost();
        if (!$host) {
            return $new;
        }
        if ($uri->getPort()) {
            $host .= ':' . $uri->getPort();
        }
        $new->_environment['HTTP_HOST'] = $host;

        return $new;
    }
public function withUri ( UriInterface $ uri , $ preserveHost = false ) { $ new = clone $ this ; $ new -> uri = $ uri ; if ( $ preserveHost && $ this -> hasHeader ( 'Host' ) ) { return $ new ; } $ host = $ uri -> getHost ( ) ; if ( ! $ host ) { return $ new ; } if ( $ uri -> getPort ( ) ) { $ host .= ':' . $ uri -> getPort ( ) ; } $ new -> _environment [ 'HTTP_HOST' ] = $ host ; return $ new ; }
Return an instance with the specified uri

*Warning* Replacing the Uri will not update the `base`, `webroot`,
and `url` attributes.

@param \Psr\Http\Message\UriInterface $uri The new request uri
@param bool $preserveHost Whether or not the host should be retained.
@return static
Return an instance with the specified uri