1: <?php declare(strict_types=1);
2:
3: namespace Salient\Http;
4:
5: use Salient\Contract\Http\HasInnerHeaders;
6: use Salient\Contract\Http\HeadersInterface;
7: use Salient\Core\Concern\ImmutableTrait;
8:
9: /**
10: * @api
11: *
12: * @phpstan-require-implements HasInnerHeaders
13: */
14: trait HasInnerHeadersTrait
15: {
16: use ImmutableTrait;
17:
18: protected HeadersInterface $Headers;
19:
20: /**
21: * @inheritDoc
22: */
23: public function getInnerHeaders(): HeadersInterface
24: {
25: return $this->Headers;
26: }
27:
28: /**
29: * @inheritDoc
30: */
31: public function getHeaders(): array
32: {
33: return $this->Headers->getHeaders();
34: }
35:
36: /**
37: * @inheritDoc
38: */
39: public function hasHeader(string $name): bool
40: {
41: return $this->Headers->hasHeader($name);
42: }
43:
44: /**
45: * @inheritDoc
46: */
47: public function getHeader(string $name): array
48: {
49: return $this->Headers->getHeader($name);
50: }
51:
52: /**
53: * @inheritDoc
54: */
55: public function getHeaderLine(string $name): string
56: {
57: return $this->Headers->getHeaderLine($name);
58: }
59:
60: /**
61: * @inheritDoc
62: */
63: public function getHeaderLines(): array
64: {
65: return $this->Headers->getHeaderLines();
66: }
67:
68: /**
69: * @inheritDoc
70: */
71: public function getHeaderValues(string $name): array
72: {
73: return $this->Headers->getHeaderValues($name);
74: }
75:
76: /**
77: * @inheritDoc
78: */
79: public function getFirstHeaderValue(string $name): string
80: {
81: return $this->Headers->getFirstHeaderValue($name);
82: }
83:
84: /**
85: * @inheritDoc
86: */
87: public function getLastHeaderValue(string $name): string
88: {
89: return $this->Headers->getLastHeaderValue($name);
90: }
91:
92: /**
93: * @inheritDoc
94: */
95: public function getOnlyHeaderValue(string $name, bool $orSame = false): string
96: {
97: return $this->Headers->getOnlyHeaderValue($name, $orSame);
98: }
99:
100: /**
101: * @return static
102: */
103: public function withHeader(string $name, $value): self
104: {
105: return $this->with('Headers', $this->Headers->set($name, $value));
106: }
107:
108: /**
109: * @return static
110: */
111: public function withAddedHeader(string $name, $value): self
112: {
113: return $this->with('Headers', $this->Headers->addValue($name, $value));
114: }
115:
116: /**
117: * @return static
118: */
119: public function withoutHeader(string $name): self
120: {
121: return $this->with('Headers', $this->Headers->unset($name));
122: }
123: }
124: