Skip to content

Commit fa2b2b6

Browse files
committed
Причесывание
1 parent bbc4e28 commit fa2b2b6

File tree

3 files changed

+74
-82
lines changed

3 files changed

+74
-82
lines changed

src/Services/PSR/PSR7/Message.php

Lines changed: 47 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
*/
1717
class Message implements MessageInterface
1818
{
19-
const DEFAULT_HTTP_VERSION = '1.1';
19+
protected const DEFAULT_HTTP_VERSION = '1.1';
2020

2121
/**
22-
* @var HttpRequest
22+
* @var HttpRequest $request
2323
*/
2424
protected $request;
2525

2626
/**
27-
* @var string
27+
* @var string $httpVersion
2828
*/
2929
protected $httpVersion;
3030

@@ -33,15 +33,15 @@ class Message implements MessageInterface
3333
*/
3434

3535
protected $body;
36+
3637
/**
37-
* @var UriInterface
38+
* @var UriInterface $uri
3839
*/
39-
4040
protected $uri;
41+
4142
/**
42-
* @var array
43+
* @var array $attributes
4344
*/
44-
4545
protected $attributes;
4646

4747
/**
@@ -57,7 +57,7 @@ public function __construct(
5757
string $httpVersion = null,
5858
$body = null,
5959
array $attributes = []
60-
){
60+
) {
6161
$this->request = $request;
6262
$this->httpVersion = $httpVersion;
6363
$this->body = $body;
@@ -73,27 +73,7 @@ public function __construct(
7373
}
7474

7575
/**
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
9777
*/
9878
public function getProtocolVersion()
9979
{
@@ -105,18 +85,16 @@ public function getProtocolVersion()
10585
return $this->httpVersion = str_replace(['HTTP', '/'], '', $version);
10686
}
10787

108-
10988
/**
110-
* @param string $version
111-
* @return $this|Message
89+
* @inheritDoc
11290
*/
11391
public function withProtocolVersion($version)
11492
{
11593
return new static($this->request, $version, $this->body, $this->attributes);
11694
}
11795

11896
/**
119-
* @return array|string[][]
97+
* @inheritDoc
12098
*/
12199
public function getHeaders()
122100
{
@@ -130,22 +108,23 @@ public function getHeaders()
130108
}
131109

132110
/**
133-
* @param string $name
134-
* @return bool
111+
* @inheritDoc
135112
*/
136113
public function hasHeader($name)
137114
{
138115
return !empty($this->getHeader($name));
139116
}
140117

118+
/**
119+
* @inheritDoc
120+
*/
141121
public function getHeader($name)
142122
{
143123
return (array)($this->request->getHeader($name) ?? []);
144124
}
145125

146126
/**
147-
* @param string $name
148-
* @return string
127+
* @inheritDoc
149128
*/
150129
public function getHeaderLine($name)
151130
{
@@ -158,9 +137,7 @@ public function getHeaderLine($name)
158137
}
159138

160139
/**
161-
* @param string $name
162-
* @param string|string[] $value
163-
* @return $this|Message
140+
* @inheritDoc
164141
*/
165142
public function withHeader($name, $value)
166143
{
@@ -170,9 +147,7 @@ public function withHeader($name, $value)
170147
}
171148

172149
/**
173-
* @param string $name
174-
* @param string|string[] $value
175-
* @return $this|Message
150+
* @inheritDoc
176151
*/
177152
public function withAddedHeader($name, $value)
178153
{
@@ -187,8 +162,7 @@ public function withAddedHeader($name, $value)
187162
}
188163

189164
/**
190-
* @param string $name
191-
* @return $this|Message
165+
* @inheritDoc
192166
*/
193167
public function withoutHeader($name)
194168
{
@@ -203,7 +177,7 @@ public function withoutHeader($name)
203177
}
204178

205179
/**
206-
* @return StreamInterface
180+
* @inheritDoc
207181
*/
208182
public function getBody()
209183
{
@@ -215,8 +189,7 @@ public function getBody()
215189
}
216190

217191
/**
218-
* @param StreamInterface $body
219-
* @return $this|Message
192+
* @inheritDoc
220193
*/
221194
public function withBody(StreamInterface $body)
222195
{
@@ -226,4 +199,30 @@ public function withBody(StreamInterface $body)
226199

227200
return new static($this->request, $this->httpVersion, $body, $this->attributes);
228201
}
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+
}
229228
}

src/Services/PSR/PSR7/PsrRequest.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,15 @@
1313
class PsrRequest extends Message implements RequestInterface
1414
{
1515
/**
16-
* @return string
16+
* @inheritDoc
1717
*/
1818
public function getRequestTarget()
1919
{
2020
return (string)$this->request->getRequestUri();
2121
}
2222

2323
/**
24-
* @param mixed $requestTarget
25-
*
26-
* @return $this|PsrRequest
24+
* @inheritDoc
2725
*/
2826
public function withRequestTarget($requestTarget)
2927
{
@@ -34,17 +32,15 @@ public function withRequestTarget($requestTarget)
3432
}
3533

3634
/**
37-
* @return string|null
35+
* @inheritDoc
3836
*/
3937
public function getMethod()
4038
{
4139
return $this->request->getRequestMethod();
4240
}
4341

4442
/**
45-
* @param string $method
46-
*
47-
* @return $this|PsrRequest
43+
* @inheritDoc
4844
*/
4945
public function withMethod($method)
5046
{
@@ -55,17 +51,15 @@ public function withMethod($method)
5551
}
5652

5753
/**
58-
* @return UriInterface
54+
* @inheritDoc
5955
*/
6056
public function getUri()
6157
{
6258
return $this->uri;
6359
}
6460

6561
/**
66-
* @param UriInterface $uri
67-
* @param false $preserveHost
68-
* @return $this|PsrRequest
62+
* @inheritDoc
6963
*/
7064
public function withUri(UriInterface $uri, $preserveHost = false)
7165
{

src/Services/PSR/PSR7/ServerPsrRequest.php

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use GuzzleHttp\Psr7\UploadedFile;
66
use Psr\Http\Message\ServerRequestInterface;
7-
use Psr\Http\Message\UploadedFileInterface;
87

98
/**
109
* Class ServerPsrRequest
@@ -88,27 +87,6 @@ public function getUploadedFiles()
8887
}, $this->request->getFileList()->toArray());
8988
}
9089

91-
/**
92-
* @return array
93-
*/
94-
private function getFileList(): array
95-
{
96-
$fileList = [];
97-
foreach ($this->request->getFileList() as $key => $file) {
98-
foreach ($file as $k => $value) {
99-
if (is_array($value)) {
100-
foreach ($value as $i => $v) {
101-
$fileList[$key][$i][$k] = $v;
102-
}
103-
} else {
104-
$fileList[$key][$k] = $v;
105-
}
106-
}
107-
}
108-
109-
return $fileList;
110-
}
111-
11290
/**
11391
* @inheritDoc
11492
*/
@@ -184,4 +162,25 @@ public function withoutAttribute($attribute): ServerRequestInterface
184162

185163
return $new;
186164
}
165+
166+
/**
167+
* @return array
168+
*/
169+
private function getFileList(): array
170+
{
171+
$fileList = [];
172+
foreach ($this->request->getFileList() as $key => $file) {
173+
foreach ($file as $k => $value) {
174+
if (is_array($value)) {
175+
foreach ($value as $i => $v) {
176+
$fileList[$key][$i][$k] = $v;
177+
}
178+
} else {
179+
$fileList[$key][$k] = $v;
180+
}
181+
}
182+
}
183+
184+
return $fileList;
185+
}
187186
}

0 commit comments

Comments
 (0)