1 | <?php |
||
16 | trait RequestTrait |
||
17 | { |
||
18 | /** @var string */ |
||
19 | private $method; |
||
20 | |||
21 | /** @var string|null */ |
||
22 | private $requestTarget; |
||
23 | |||
24 | /** @var UriInterface|null */ |
||
25 | private $uri; |
||
26 | |||
27 | 6 | public function getRequestTarget(): string |
|
28 | { |
||
29 | 6 | if (null !== $this->requestTarget) { |
|
30 | 2 | return $this->requestTarget; |
|
31 | } |
||
32 | |||
33 | 6 | if ('' === $target = $this->uri->getPath()) { |
|
34 | 2 | $target = '/'; |
|
35 | } |
||
36 | 6 | if ('' !== $this->uri->getQuery()) { |
|
37 | 3 | $target .= '?' . $this->uri->getQuery(); |
|
38 | } |
||
39 | |||
40 | 6 | return $target; |
|
41 | } |
||
42 | |||
43 | 4 | public function withRequestTarget($requestTarget): self |
|
44 | { |
||
45 | 4 | if (\preg_match('#\s#', $requestTarget)) { |
|
46 | 2 | throw new \InvalidArgumentException('Invalid request target provided; cannot contain whitespace'); |
|
47 | } |
||
48 | |||
49 | 2 | $new = clone $this; |
|
50 | 2 | $new->requestTarget = $requestTarget; |
|
51 | |||
52 | 2 | return $new; |
|
53 | } |
||
54 | |||
55 | 27 | public function getMethod(): string |
|
59 | |||
60 | 7 | public function withMethod($method): self |
|
71 | |||
72 | 31 | public function getUri(): UriInterface |
|
76 | |||
77 | 10 | public function withUri(UriInterface $uri, $preserveHost = false): self |
|
78 | { |
||
92 | |||
93 | 115 | private function updateHostFromUri(): void |
|
113 | } |
||
114 |