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