PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.4
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.4
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / vendor_prefixed / guzzlehttp / psr7 / src / Response.php

Response.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 18.4, at vendor_prefixed/guzzlehttp/psr7/src/Response.php

77 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 namespace YoastSEO_Vendor\GuzzleHttp\Psr7;
4
5 use YoastSEO_Vendor\Psr\Http\Message\ResponseInterface;
6 use YoastSEO_Vendor\Psr\Http\Message\StreamInterface;
7 /**
8 * PSR-7 response implementation.
9 */
10 class Response implements \YoastSEO_Vendor\Psr\Http\Message\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 = \YoastSEO_Vendor\GuzzleHttp\Psr7\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