Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
message.php
1<?php
2
10namespace Bitrix\Main\Web\Http;
11
13use Psr\Http\Message\MessageInterface;
14use Psr\Http\Message\StreamInterface;
15
16class Message implements MessageInterface
17{
19 protected StreamInterface $body;
20
26 public function __construct(array $headers = null, StreamInterface $body = null, string $version = null)
27 {
28 $this->headers = new HttpHeaders($headers);
29
30 if ($version !== null)
31 {
32 $this->headers->setVersion($version);
33 }
34
35 $this->body = $body ?? new Stream('php://temp', 'r+');
36 }
37
41 public function getProtocolVersion(): string
42 {
43 return $this->headers->getVersion();
44 }
45
49 public function withProtocolVersion(string $version): MessageInterface
50 {
51 if ($this->getProtocolVersion() === $version)
52 {
53 return $this;
54 }
55
56 $new = clone $this;
57 $new->headers->setVersion($version);
58
59 return $new;
60 }
61
66 {
67 return $this->headers;
68 }
69
73 public function getHeaders(): array
74 {
75 return $this->headers->getHeaders();
76 }
77
81 public function hasHeader(string $name): bool
82 {
83 return $this->headers->has($name);
84 }
85
89 public function getHeader(string $name): array
90 {
91 return $this->headers->get($name, true) ?? [];
92 }
93
97 public function getHeaderLine(string $name): string
98 {
99 return implode(',', $this->getHeader($name));
100 }
101
105 public function withHeader(string $name, $value): MessageInterface
106 {
107 $new = clone $this;
108 $new->headers->set($name, $value);
109
110 return $new;
111 }
112
116 public function withAddedHeader(string $name, $value): MessageInterface
117 {
118 $new = clone $this;
119 $new->headers->add($name, $value);
120
121 return $new;
122 }
123
127 public function withoutHeader(string $name): MessageInterface
128 {
129 $new = clone $this;
130 $new->headers->delete($name);
131
132 return $new;
133 }
134
138 public function getBody(): StreamInterface
139 {
140 return $this->body;
141 }
142
146 public function withBody(StreamInterface $body): MessageInterface
147 {
148 $new = clone $this;
149 $new->body = $body;
150
151 return $new;
152 }
153
154 public function __clone()
155 {
156 $this->headers = clone $this->headers;
157 $this->body = clone $this->body;
158 }
159}
withBody(StreamInterface $body)
Definition message.php:146
withHeader(string $name, $value)
Definition message.php:105
withAddedHeader(string $name, $value)
Definition message.php:116
getHeaderLine(string $name)
Definition message.php:97
__construct(array $headers=null, StreamInterface $body=null, string $version=null)
Definition message.php:26
withProtocolVersion(string $version)
Definition message.php:49
withoutHeader(string $name)
Definition message.php:127
StreamInterface $body
Definition message.php:19