PluginProbe
Media Cloud Sync / 1.0.0
Media Cloud Sync v1.0.0
1.4.2 1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 All 36 releases
media-cloud-sync / includes / sdk / s3 / GuzzleHttp / Psr7 / Request.php

Request.php in Media Cloud Sync 1.0.0, at includes/sdk/s3/GuzzleHttp/Psr7/Request.php

121 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Dudlewebs\WPMCS\s3\GuzzleHttp\Psr7;
4
5 use InvalidArgumentException;
6 use Dudlewebs\WPMCS\s3\Psr\Http\Message\RequestInterface;
7 use Dudlewebs\WPMCS\s3\Psr\Http\Message\StreamInterface;
8 use Dudlewebs\WPMCS\s3\Psr\Http\Message\UriInterface;
9 /**
10 * PSR-7 request implementation.
11 */
12 class Request implements RequestInterface
13 {
14 use MessageTrait;
15 /** @var string */
16 private $method;
17 /** @var string|null */
18 private $requestTarget;
19 /** @var UriInterface */
20 private $uri;
21 /**
22 * @param string $method HTTP method
23 * @param string|UriInterface $uri URI
24 * @param array $headers Request headers
25 * @param string|resource|StreamInterface|null $body Request body
26 * @param string $version Protocol version
27 */
28 public function __construct($method, $uri, array $headers = [], $body = null, $version = '1.1')
29 {
30 $this->assertMethod($method);
31 if (!$uri instanceof UriInterface) {
32 $uri = new Uri($uri);
33 }
34 $this->method = \strtoupper($method);
35 $this->uri = $uri;
36 $this->setHeaders($headers);
37 $this->protocol = $version;
38 if (!isset($this->headerNames['host'])) {
39 $this->updateHostFromUri();
40 }
41 if ($body !== '' && $body !== null) {
42 $this->stream = Utils::streamFor($body);
43 }
44 }
45 public function getRequestTarget()
46 {
47 if ($this->requestTarget !== null) {
48 return $this->requestTarget;
49 }
50 $target = $this->uri->getPath();
51 if ($target == '') {
52 $target = '/';
53 }
54 if ($this->uri->getQuery() != '') {
55 $target .= '?' . $this->uri->getQuery();
56 }
57 return $target;
58 }
59 public function withRequestTarget($requestTarget)
60 {
61 if (\preg_match('#\\s#', $requestTarget)) {
62 throw new InvalidArgumentException('Invalid request target provided; cannot contain whitespace');
63 }
64 $new = clone $this;
65 $new->requestTarget = $requestTarget;
66 return $new;
67 }
68 public function getMethod()
69 {
70 return $this->method;
71 }
72 public function withMethod($method)
73 {
74 $this->assertMethod($method);
75 $new = clone $this;
76 $new->method = \strtoupper($method);
77 return $new;
78 }
79 public function getUri()
80 {
81 return $this->uri;
82 }
83 public function withUri(UriInterface $uri, $preserveHost = \false)
84 {
85 if ($uri === $this->uri) {
86 return $this;
87 }
88 $new = clone $this;
89 $new->uri = $uri;
90 if (!$preserveHost || !isset($this->headerNames['host'])) {
91 $new->updateHostFromUri();
92 }
93 return $new;
94 }
95 private function updateHostFromUri()
96 {
97 $host = $this->uri->getHost();
98 if ($host == '') {
99 return;
100 }
101 if (($port = $this->uri->getPort()) !== null) {
102 $host .= ':' . $port;
103 }
104 if (isset($this->headerNames['host'])) {
105 $header = $this->headerNames['host'];
106 } else {
107 $header = 'Host';
108 $this->headerNames['host'] = 'Host';
109 }
110 // Ensure Host is the first header.
111 // See: http://tools.ietf.org/html/rfc7230#section-5.4
112 $this->headers = [$header => [$host]] + $this->headers;
113 }
114 private function assertMethod($method)
115 {
116 if (!\is_string($method) || $method === '') {
117 throw new \InvalidArgumentException('Method must be a non-empty string.');
118 }
119 }
120 }
121