| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 3 declare (strict_types=1); 4 namespace WordPress\AiClientDependencies\Nyholm\Psr7; 5 6 use WordPress\AiClientDependencies\Psr\Http\Message\RequestInterface; 7 use WordPress\AiClientDependencies\Psr\Http\Message\UriInterface; 8 /** 9 * @author Michael Dowling and contributors to guzzlehttp/psr7 10 * @author Tobias Nyholm <tobias.nyholm@gmail.com> 11 * @author Martijn van der Ven <martijn@vanderven.se> 12 * 13 * @internal should not be used outside of Nyholm/Psr7 as it does not fall under our BC promise 14 */ 15 trait RequestTrait 16 { 17 /** @var string */ 18 private $method; 19 /** @var string|null */ 20 private $requestTarget; 21 /** @var UriInterface|null */ 22 private $uri; 23 public function getRequestTarget(): string 24 { 25 if (null !== $this->requestTarget) { 26 return $this->requestTarget; 27 } 28 if ('' === $target = $this->uri->getPath()) { 29 $target = '/'; 30 } 31 if ('' !== $this->uri->getQuery()) { 32 $target .= '?' . $this->uri->getQuery(); 33 } 34 return $target; 35 } 36 /** 37 * @return static 38 */ 39 public function withRequestTarget($requestTarget): RequestInterface 40 { 41 if (!\is_string($requestTarget)) { 42 throw new \InvalidArgumentException('Request target must be a string'); 43 } 44 if (\preg_match('#\s#', $requestTarget)) { 45 throw new \InvalidArgumentException('Invalid request target provided; cannot contain whitespace'); 46 } 47 $new = clone $this; 48 $new->requestTarget = $requestTarget; 49 return $new; 50 } 51 public function getMethod(): string 52 { 53 return $this->method; 54 } 55 /** 56 * @return static 57 */ 58 public function withMethod($method): RequestInterface 59 { 60 if (!\is_string($method)) { 61 throw new \InvalidArgumentException('Method must be a string'); 62 } 63 $new = clone $this; 64 $new->method = $method; 65 return $new; 66 } 67 public function getUri(): UriInterface 68 { 69 return $this->uri; 70 } 71 /** 72 * @return static 73 */ 74 public function withUri(UriInterface $uri, $preserveHost = \false): RequestInterface 75 { 76 if ($uri === $this->uri) { 77 return $this; 78 } 79 $new = clone $this; 80 $new->uri = $uri; 81 if (!$preserveHost || !$this->hasHeader('Host')) { 82 $new->updateHostFromUri(); 83 } 84 return $new; 85 } 86 private function updateHostFromUri(): void 87 { 88 if ('' === $host = $this->uri->getHost()) { 89 return; 90 } 91 if (null !== $port = $this->uri->getPort()) { 92 $host .= ':' . $port; 93 } 94 if (isset($this->headerNames['host'])) { 95 $header = $this->headerNames['host']; 96 } else { 97 $this->headerNames['host'] = $header = 'Host'; 98 } 99 // Ensure Host is the first header. 100 // See: http://tools.ietf.org/html/rfc7230#section-5.4 101 $this->headers = [$header => [$host]] + $this->headers; 102 } 103 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Sat Jun 13 09:38:55 2026 | Cross-referenced by PHPXref |