original_string: 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;
      }
code: 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;
      }
code_tokens: 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 ; }
docstring: 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
docstring_tokens: Return an instance with the specified uri