PluginProbe
Media Cloud Sync / 1.3.11
Media Cloud Sync v1.3.11
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 1.2.9 All 35 releases
media-cloud-sync / includes / sdk / s3 / GuzzleHttp / Psr7 / Response.php

Response.php in Media Cloud Sync 1.3.11, at includes/sdk/s3/GuzzleHttp/Psr7/Response.php

79 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare (strict_types=1);
4 namespace Dudlewebs\WPMCS\s3\GuzzleHttp\Psr7;
5
6 use Dudlewebs\WPMCS\s3\Psr\Http\Message\ResponseInterface;
7 use Dudlewebs\WPMCS\s3\Psr\Http\Message\StreamInterface;
8 /**
9 * PSR-7 response implementation.
10 */
11 class Response implements ResponseInterface
12 {
13 use MessageTrait;
14 /** Map of standard HTTP status code/reason phrases */
15 private const PHRASES = [100 => 'Continue', 101 => 'Switching Protocols', 102 => 'Processing', 200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content', 207 => 'Multi-status', 208 => 'Already Reported', 300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy', 306 => 'Switch Proxy', 307 => 'Temporary Redirect', 308 => 'Permanent Redirect', 400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Time-out', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Large', 415 => 'Unsupported Media Type', 416 => 'Requested range not satisfiable', 417 => 'Expectation Failed', 418 => 'I\'m a teapot', 422 => 'Unprocessable Entity', 423 => 'Locked', 424 => 'Failed Dependency', 425 => 'Unordered Collection', 426 => 'Upgrade Required', 428 => 'Precondition Required', 429 => 'Too Many Requests', 431 => 'Request Header Fields Too Large', 451 => 'Unavailable For Legal Reasons', 500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Time-out', 505 => 'HTTP Version not supported', 506 => 'Variant Also Negotiates', 507 => 'Insufficient Storage', 508 => 'Loop Detected', 510 => 'Not Extended', 511 => 'Network Authentication Required'];
16 /** @var string */
17 private $reasonPhrase;
18 /** @var int */
19 private $statusCode;
20 /**
21 * @param int $status Status code
22 * @param (string|string[])[] $headers Response headers
23 * @param string|resource|StreamInterface|null $body Response body
24 * @param string $version Protocol version
25 * @param string|null $reason Reason phrase (when empty a default will be used based on the status code)
26 */
27 public function __construct(int $status = 200, array $headers = [], $body = null, string $version = '1.1', ?string $reason = null)
28 {
29 $this->assertStatusCodeRange($status);
30 $this->statusCode = $status;
31 if ($body !== '' && $body !== null) {
32 $this->stream = Utils::streamFor($body);
33 }
34 $this->setHeaders($headers);
35 if ($reason == '' && isset(self::PHRASES[$this->statusCode])) {
36 $this->reasonPhrase = self::PHRASES[$this->statusCode];
37 } else {
38 $this->reasonPhrase = (string) $reason;
39 }
40 $this->protocol = $version;
41 }
42 public function getStatusCode() : int
43 {
44 return $this->statusCode;
45 }
46 public function getReasonPhrase() : string
47 {
48 return $this->reasonPhrase;
49 }
50 public function withStatus($code, $reasonPhrase = '') : ResponseInterface
51 {
52 $this->assertStatusCodeIsInteger($code);
53 $code = (int) $code;
54 $this->assertStatusCodeRange($code);
55 $new = clone $this;
56 $new->statusCode = $code;
57 if ($reasonPhrase == '' && isset(self::PHRASES[$new->statusCode])) {
58 $reasonPhrase = self::PHRASES[$new->statusCode];
59 }
60 $new->reasonPhrase = (string) $reasonPhrase;
61 return $new;
62 }
63 /**
64 * @param mixed $statusCode
65 */
66 private function assertStatusCodeIsInteger($statusCode) : void
67 {
68 if (\filter_var($statusCode, \FILTER_VALIDATE_INT) === \false) {
69 throw new \InvalidArgumentException('Status code must be an integer value.');
70 }
71 }
72 private function assertStatusCodeRange(int $statusCode) : void
73 {
74 if ($statusCode < 100 || $statusCode >= 600) {
75 throw new \InvalidArgumentException('Status code must be an integer value between 1xx and 5xx.');
76 }
77 }
78 }
79