16
16
*/
17
17
class Message implements MessageInterface
18
18
{
19
- const DEFAULT_HTTP_VERSION = '1.1 ' ;
19
+ protected const DEFAULT_HTTP_VERSION = '1.1 ' ;
20
20
21
21
/**
22
- * @var HttpRequest
22
+ * @var HttpRequest $request
23
23
*/
24
24
protected $ request ;
25
25
26
26
/**
27
- * @var string
27
+ * @var string $httpVersion
28
28
*/
29
29
protected $ httpVersion ;
30
30
@@ -33,15 +33,15 @@ class Message implements MessageInterface
33
33
*/
34
34
35
35
protected $ body ;
36
+
36
37
/**
37
- * @var UriInterface
38
+ * @var UriInterface $uri
38
39
*/
39
-
40
40
protected $ uri ;
41
+
41
42
/**
42
- * @var array
43
+ * @var array $attributes
43
44
*/
44
-
45
45
protected $ attributes ;
46
46
47
47
/**
@@ -57,7 +57,7 @@ public function __construct(
57
57
string $ httpVersion = null ,
58
58
$ body = null ,
59
59
array $ attributes = []
60
- ){
60
+ ) {
61
61
$ this ->request = $ request ;
62
62
$ this ->httpVersion = $ httpVersion ;
63
63
$ this ->body = $ body ;
@@ -73,27 +73,7 @@ public function __construct(
73
73
}
74
74
75
75
/**
76
- * @param HttpRequest $request
77
- *
78
- * @return boolean
79
- */
80
- private function needCheckBody (HttpRequest $ request )
81
- {
82
- $ method = strtolower ($ request ->getRequestMethod ());
83
- return in_array ($ method , ['post ' , 'put ' ]);
84
- }
85
-
86
- private function getCurrentLink ()
87
- {
88
- $ server = $ this ->request ->getServer ();
89
- return ($ server ->get ('HTTPS ' ) === 'on ' ? "https " : "http " ).
90
- ":// " .
91
- $ server ->get ('HTTP_HOST ' ).
92
- $ server ->get ('REQUEST_URI ' );
93
- }
94
-
95
- /**
96
- * @return string
76
+ * @inheritDoc
97
77
*/
98
78
public function getProtocolVersion ()
99
79
{
@@ -105,18 +85,16 @@ public function getProtocolVersion()
105
85
return $ this ->httpVersion = str_replace (['HTTP ' , '/ ' ], '' , $ version );
106
86
}
107
87
108
-
109
88
/**
110
- * @param string $version
111
- * @return $this|Message
89
+ * @inheritDoc
112
90
*/
113
91
public function withProtocolVersion ($ version )
114
92
{
115
93
return new static ($ this ->request , $ version , $ this ->body , $ this ->attributes );
116
94
}
117
95
118
96
/**
119
- * @return array|string[][]
97
+ * @inheritDoc
120
98
*/
121
99
public function getHeaders ()
122
100
{
@@ -130,22 +108,23 @@ public function getHeaders()
130
108
}
131
109
132
110
/**
133
- * @param string $name
134
- * @return bool
111
+ * @inheritDoc
135
112
*/
136
113
public function hasHeader ($ name )
137
114
{
138
115
return !empty ($ this ->getHeader ($ name ));
139
116
}
140
117
118
+ /**
119
+ * @inheritDoc
120
+ */
141
121
public function getHeader ($ name )
142
122
{
143
123
return (array )($ this ->request ->getHeader ($ name ) ?? []);
144
124
}
145
125
146
126
/**
147
- * @param string $name
148
- * @return string
127
+ * @inheritDoc
149
128
*/
150
129
public function getHeaderLine ($ name )
151
130
{
@@ -158,9 +137,7 @@ public function getHeaderLine($name)
158
137
}
159
138
160
139
/**
161
- * @param string $name
162
- * @param string|string[] $value
163
- * @return $this|Message
140
+ * @inheritDoc
164
141
*/
165
142
public function withHeader ($ name , $ value )
166
143
{
@@ -170,9 +147,7 @@ public function withHeader($name, $value)
170
147
}
171
148
172
149
/**
173
- * @param string $name
174
- * @param string|string[] $value
175
- * @return $this|Message
150
+ * @inheritDoc
176
151
*/
177
152
public function withAddedHeader ($ name , $ value )
178
153
{
@@ -187,8 +162,7 @@ public function withAddedHeader($name, $value)
187
162
}
188
163
189
164
/**
190
- * @param string $name
191
- * @return $this|Message
165
+ * @inheritDoc
192
166
*/
193
167
public function withoutHeader ($ name )
194
168
{
@@ -203,7 +177,7 @@ public function withoutHeader($name)
203
177
}
204
178
205
179
/**
206
- * @return StreamInterface
180
+ * @inheritDoc
207
181
*/
208
182
public function getBody ()
209
183
{
@@ -215,8 +189,7 @@ public function getBody()
215
189
}
216
190
217
191
/**
218
- * @param StreamInterface $body
219
- * @return $this|Message
192
+ * @inheritDoc
220
193
*/
221
194
public function withBody (StreamInterface $ body )
222
195
{
@@ -226,4 +199,30 @@ public function withBody(StreamInterface $body)
226
199
227
200
return new static ($ this ->request , $ this ->httpVersion , $ body , $ this ->attributes );
228
201
}
202
+
203
+ /**
204
+ * @param HttpRequest $request Битриксовый Request.
205
+ *
206
+ * @return boolean
207
+ */
208
+ private function needCheckBody (HttpRequest $ request )
209
+ {
210
+ $ method = strtolower ($ request ->getRequestMethod ());
211
+
212
+ return in_array ($ method , ['post ' , 'put ' ]);
213
+ }
214
+
215
+ /**
216
+ * Текущий URL.
217
+ *
218
+ * @return string
219
+ */
220
+ private function getCurrentLink () : string
221
+ {
222
+ $ server = $ this ->request ->getServer ();
223
+ return ($ server ->get ('HTTPS ' ) === 'on ' ? 'https ' : 'http ' ).
224
+ ':// ' .
225
+ $ server ->get ('HTTP_HOST ' ).
226
+ $ server ->get ('REQUEST_URI ' );
227
+ }
229
228
}
0 commit comments