Skip to content

Request: withUri Example

Terry L edited this page Jun 20, 2020 · 3 revisions

Shieldon\Psr7\Request

Extends Message.

withUri($uri, $preserveHost)

Returns an instance with the provided URI.

  • param UriInterface uri * New request URI to use.
  • param string preserveHost * Preserve the original state of the Host header.
  • return static

Example:

$request = new Request('GET', 'https://terryl.in/zh/', '', [], '1.1');

$newRequest = $request->withUri(new Uri('https://play.google.com'));
$newRequest2 = $newRequest->withUri(new Uri('https://www.facebook.com'), true);

echo $newRequest->getUri()->getHost();
// Outputs: play.google.com

echo $newRequest2->getUri()->getHost();
// Outputs: terryl.in
Clone this wiki locally