/** * Returns an instance with the provided URI. * * @param UriInterface $uri New request URI to use. * @param bool $preserveHost Preserve the original state of the Host header. * @access public * @return self */ public function withUri(UriInterface $uri, $preserveHost = false) { $this->uri = $uri; $host = $this->uri->getHost(); if ($preserveHost) { if ($host != '' && !$this->hasHeader('Host')) { $this->withHeader('Host', $host); } return $this; } if ($host != '') { $this->withHeader('Host', $host); } return $this; }
public function testSetHostSetsValue() { $url = 'http://example.com/path'; $uri = new URI($url); $expected = 'http://another.com/path'; $uri->setHost('another.com'); $this->assertEquals('another.com', $uri->getHost()); $this->assertEquals($expected, (string) $uri); }