PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.20
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.20
1.10.20 1.10.19 1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 1.10.1 1.10.0 1.9.17 1.9.15 1.9.16 All 164 releases
woocommerce-pos / vendor_prefixed / guzzlehttp / psr7 / src / Response.php

Response.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.20, at vendor_prefixed/guzzlehttp/psr7/src/Response.php

76 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 WCPOS\Vendor\GuzzleHttp\Psr7;
5
6 use WCPOS\Vendor\Psr\Http\Message\ResponseInterface;
7 use WCPOS\Vendor\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 private string $reasonPhrase;
17 private int $statusCode;
18 /**
19 * @param int $status Status code
20 * @param (string|string[])[] $headers Response headers
21 * @param string|resource|StreamInterface|null $body Response body
22 * @param string $version Protocol version
23 * @param string|null $reason Reason phrase (when empty a default will be used based on the status code)
24 */
25 public function __construct(int $status = 200, array $headers = [], $body = null, string $version = '1.1', ?string $reason = null)
26 {
27 $this->assertStatusCodeRange($status);
28 $this->assertProtocolVersion($version);
29 $this->statusCode = $status;
30 if ($body !== '' && $body !== null) {
31 $this->stream = Utils::streamFor($body);
32 }
33 $this->setHeaders($headers);
34 if ($reason == '' && isset(self::PHRASES[$this->statusCode])) {
35 $reasonPhrase = self::PHRASES[$this->statusCode];
36 } else {
37 $reasonPhrase = (string) $reason;
38 }
39 $this->assertReasonPhrase($reasonPhrase);
40 $this->reasonPhrase = $reasonPhrase;
41 $this->protocol = $version;
42 }
43 public function getStatusCode() : int
44 {
45 return $this->statusCode;
46 }
47 public function getReasonPhrase() : string
48 {
49 return $this->reasonPhrase;
50 }
51 public function withStatus(int $code, string $reasonPhrase = '') : ResponseInterface
52 {
53 $this->assertStatusCodeRange($code);
54 $new = clone $this;
55 $new->statusCode = $code;
56 if ($reasonPhrase === '' && isset(self::PHRASES[$new->statusCode])) {
57 $reasonPhrase = self::PHRASES[$new->statusCode];
58 }
59 $this->assertReasonPhrase($reasonPhrase);
60 $new->reasonPhrase = $reasonPhrase;
61 return $new;
62 }
63 private function assertStatusCodeRange(int $statusCode) : void
64 {
65 if ($statusCode < 100 || $statusCode >= 600) {
66 throw new \InvalidArgumentException('Status code must be an integer value between 1xx and 5xx.');
67 }
68 }
69 private function assertReasonPhrase(string $reasonPhrase) : void
70 {
71 if (!Rfc9112::isValidReasonPhrase($reasonPhrase)) {
72 throw new \InvalidArgumentException('Reason phrase must not contain invalid control characters.');
73 }
74 }
75 }
76