diff --git a/src/Services/PSR/PSR7/Message.php b/src/Services/PSR/PSR7/Message.php index 127cef2..9a6731f 100644 --- a/src/Services/PSR/PSR7/Message.php +++ b/src/Services/PSR/PSR7/Message.php @@ -16,15 +16,15 @@ */ class Message implements MessageInterface { - const DEFAULT_HTTP_VERSION = '1.1'; + protected const DEFAULT_HTTP_VERSION = '1.1'; /** - * @var HttpRequest + * @var HttpRequest $request */ protected $request; /** - * @var string + * @var string $httpVersion */ protected $httpVersion; @@ -33,15 +33,15 @@ class Message implements MessageInterface */ protected $body; + /** - * @var UriInterface + * @var UriInterface $uri */ - protected $uri; + /** - * @var array + * @var array $attributes */ - protected $attributes; /** @@ -57,7 +57,7 @@ public function __construct( string $httpVersion = null, $body = null, array $attributes = [] - ){ + ) { $this->request = $request; $this->httpVersion = $httpVersion; $this->body = $body; @@ -73,27 +73,7 @@ public function __construct( } /** - * @param HttpRequest $request - * - * @return boolean - */ - private function needCheckBody(HttpRequest $request) - { - $method = strtolower($request->getRequestMethod()); - return in_array($method, ['post', 'put']); - } - - private function getCurrentLink() - { - $server = $this->request->getServer(); - return ($server->get('HTTPS') === 'on' ? "https" : "http"). - "://". - $server->get('HTTP_HOST'). - $server->get('REQUEST_URI'); - } - - /** - * @return string + * @inheritDoc */ public function getProtocolVersion() { @@ -105,10 +85,8 @@ public function getProtocolVersion() return $this->httpVersion = str_replace(['HTTP', '/'], '', $version); } - /** - * @param string $version - * @return $this|Message + * @inheritDoc */ public function withProtocolVersion($version) { @@ -116,7 +94,7 @@ public function withProtocolVersion($version) } /** - * @return array|string[][] + * @inheritDoc */ public function getHeaders() { @@ -130,22 +108,23 @@ public function getHeaders() } /** - * @param string $name - * @return bool + * @inheritDoc */ public function hasHeader($name) { return !empty($this->getHeader($name)); } + /** + * @inheritDoc + */ public function getHeader($name) { return (array)($this->request->getHeader($name) ?? []); } /** - * @param string $name - * @return string + * @inheritDoc */ public function getHeaderLine($name) { @@ -158,9 +137,7 @@ public function getHeaderLine($name) } /** - * @param string $name - * @param string|string[] $value - * @return $this|Message + * @inheritDoc */ public function withHeader($name, $value) { @@ -170,9 +147,7 @@ public function withHeader($name, $value) } /** - * @param string $name - * @param string|string[] $value - * @return $this|Message + * @inheritDoc */ public function withAddedHeader($name, $value) { @@ -187,8 +162,7 @@ public function withAddedHeader($name, $value) } /** - * @param string $name - * @return $this|Message + * @inheritDoc */ public function withoutHeader($name) { @@ -203,7 +177,7 @@ public function withoutHeader($name) } /** - * @return StreamInterface + * @inheritDoc */ public function getBody() { @@ -215,8 +189,7 @@ public function getBody() } /** - * @param StreamInterface $body - * @return $this|Message + * @inheritDoc */ public function withBody(StreamInterface $body) { @@ -226,4 +199,30 @@ public function withBody(StreamInterface $body) return new static($this->request, $this->httpVersion, $body, $this->attributes); } + + /** + * @param HttpRequest $request Битриксовый Request. + * + * @return boolean + */ + private function needCheckBody(HttpRequest $request) + { + $method = strtolower($request->getRequestMethod()); + + return in_array($method, ['post', 'put']); + } + + /** + * Текущий URL. + * + * @return string + */ + private function getCurrentLink() : string + { + $server = $this->request->getServer(); + return ($server->get('HTTPS') === 'on' ? 'https' : 'http'). + '://'. + $server->get('HTTP_HOST'). + $server->get('REQUEST_URI'); + } } diff --git a/src/Services/PSR/PSR7/PsrRequest.php b/src/Services/PSR/PSR7/PsrRequest.php index 4630977..9222557 100644 --- a/src/Services/PSR/PSR7/PsrRequest.php +++ b/src/Services/PSR/PSR7/PsrRequest.php @@ -13,7 +13,7 @@ class PsrRequest extends Message implements RequestInterface { /** - * @return string + * @inheritDoc */ public function getRequestTarget() { @@ -21,9 +21,7 @@ public function getRequestTarget() } /** - * @param mixed $requestTarget - * - * @return $this|PsrRequest + * @inheritDoc */ public function withRequestTarget($requestTarget) { @@ -34,7 +32,7 @@ public function withRequestTarget($requestTarget) } /** - * @return string|null + * @inheritDoc */ public function getMethod() { @@ -42,9 +40,7 @@ public function getMethod() } /** - * @param string $method - * - * @return $this|PsrRequest + * @inheritDoc */ public function withMethod($method) { @@ -55,7 +51,7 @@ public function withMethod($method) } /** - * @return UriInterface + * @inheritDoc */ public function getUri() { @@ -63,9 +59,7 @@ public function getUri() } /** - * @param UriInterface $uri - * @param false $preserveHost - * @return $this|PsrRequest + * @inheritDoc */ public function withUri(UriInterface $uri, $preserveHost = false) { diff --git a/src/Services/PSR/PSR7/ServerPsrRequest.php b/src/Services/PSR/PSR7/ServerPsrRequest.php index f11b25d..ef7098e 100644 --- a/src/Services/PSR/PSR7/ServerPsrRequest.php +++ b/src/Services/PSR/PSR7/ServerPsrRequest.php @@ -4,7 +4,6 @@ use GuzzleHttp\Psr7\UploadedFile; use Psr\Http\Message\ServerRequestInterface; -use Psr\Http\Message\UploadedFileInterface; /** * Class ServerPsrRequest @@ -88,27 +87,6 @@ public function getUploadedFiles() }, $this->request->getFileList()->toArray()); } - /** - * @return array - */ - private function getFileList(): array - { - $fileList = []; - foreach ($this->request->getFileList() as $key => $file) { - foreach ($file as $k => $value) { - if (is_array($value)) { - foreach ($value as $i => $v) { - $fileList[$key][$i][$k] = $v; - } - } else { - $fileList[$key][$k] = $v; - } - } - } - - return $fileList; - } - /** * @inheritDoc */ @@ -184,4 +162,25 @@ public function withoutAttribute($attribute): ServerRequestInterface return $new; } + + /** + * @return array + */ + private function getFileList(): array + { + $fileList = []; + foreach ($this->request->getFileList() as $key => $file) { + foreach ($file as $k => $value) { + if (is_array($value)) { + foreach ($value as $i => $v) { + $fileList[$key][$i][$k] = $v; + } + } else { + $fileList[$key][$k] = $v; + } + } + } + + return $fileList; + } }