PluginProbe
Media Cloud Sync / 1.2.10
Media Cloud Sync v1.2.10
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.2.10, at includes/sdk/s3/GuzzleHttp/Psr7/Response.php

77 lines 4.2 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 Dudlewebs\WPMCS\s3\Psr\Http\Message\ResponseInterface;
6 use Dudlewebs\WPMCS\s3\Psr\Http\Message\StreamInterface;
7 /**
8 * PSR-7 response implementation.
9 */
10 class Response implements ResponseInterface
11 {
12 use MessageTrait;
13 /** @var array Map of standard HTTP status code/reason phrases */
14 private static $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', 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', 511 => 'Network Authentication Required'];
15 /** @var string */
16 private $reasonPhrase = '';
17 /** @var int */
18 private $statusCode = 200;
19 /**
20 * @param int $status Status code
21 * @param array $headers Response headers
22 * @param string|resource|StreamInterface|null $body Response body
23 * @param string $version Protocol version
24 * @param string|null $reason Reason phrase (when empty a default will be used based on the status code)
25 */
26 public function __construct($status = 200, array $headers = [], $body = null, $version = '1.1', $reason = null)
27 {
28 $this->assertStatusCodeIsInteger($status);
29 $status = (int) $status;
30 $this->assertStatusCodeRange($status);
31 $this->statusCode = $status;
32 if ($body !== '' && $body !== null) {
33 $this->stream = Utils::streamFor($body);
34 }
35 $this->setHeaders($headers);
36 if ($reason == '' && isset(self::$phrases[$this->statusCode])) {
37 $this->reasonPhrase = self::$phrases[$this->statusCode];
38 } else {
39 $this->reasonPhrase = (string) $reason;
40 }
41 $this->protocol = $version;
42 }
43 public function getStatusCode()
44 {
45 return $this->statusCode;
46 }
47 public function getReasonPhrase()
48 {
49 return $this->reasonPhrase;
50 }
51 public function withStatus($code, $reasonPhrase = '')
52 {
53 $this->assertStatusCodeIsInteger($code);
54 $code = (int) $code;
55 $this->assertStatusCodeRange($code);
56 $new = clone $this;
57 $new->statusCode = $code;
58 if ($reasonPhrase == '' && isset(self::$phrases[$new->statusCode])) {
59 $reasonPhrase = self::$phrases[$new->statusCode];
60 }
61 $new->reasonPhrase = (string) $reasonPhrase;
62 return $new;
63 }
64 private function assertStatusCodeIsInteger($statusCode)
65 {
66 if (\filter_var($statusCode, \FILTER_VALIDATE_INT) === \false) {
67 throw new \InvalidArgumentException('Status code must be an integer value.');
68 }
69 }
70 private function assertStatusCodeRange($statusCode)
71 {
72 if ($statusCode < 100 || $statusCode >= 600) {
73 throw new \InvalidArgumentException('Status code must be an integer value between 1xx and 5xx.');
74 }
75 }
76 }
77