| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 3 declare (strict_types=1); 4 namespace WordPress\AiClientDependencies\Nyholm\Psr7; 5 6 use WordPress\AiClientDependencies\Psr\Http\Message\ResponseInterface; 7 use WordPress\AiClientDependencies\Psr\Http\Message\StreamInterface; 8 /** 9 * @author Michael Dowling and contributors to guzzlehttp/psr7 10 * @author Tobias Nyholm <tobias.nyholm@gmail.com> 11 * @author Martijn van der Ven <martijn@vanderven.se> 12 * 13 * @final This class should never be extended. See https://github.com/Nyholm/psr7/blob/master/doc/final.md 14 */ 15 class Response implements ResponseInterface 16 { 17 use MessageTrait; 18 /** @var array Map of standard HTTP status code/reason phrases */ 19 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', 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']; 20 /** @var string */ 21 private $reasonPhrase = ''; 22 /** @var int */ 23 private $statusCode; 24 /** 25 * @param int $status Status code 26 * @param array $headers Response headers 27 * @param string|resource|StreamInterface|null $body Response body 28 * @param string $version Protocol version 29 * @param string|null $reason Reason phrase (when empty a default will be used based on the status code) 30 */ 31 public function __construct(int $status = 200, array $headers = [], $body = null, string $version = '1.1', ?string $reason = null) 32 { 33 // If we got no body, defer initialization of the stream until Response::getBody() 34 if ('' !== $body && null !== $body) { 35 $this->stream = Stream::create($body); 36 } 37 $this->statusCode = $status; 38 $this->setHeaders($headers); 39 if (null === $reason && isset(self::PHRASES[$this->statusCode])) { 40 $this->reasonPhrase = self::PHRASES[$status]; 41 } else { 42 $this->reasonPhrase = $reason ?? ''; 43 } 44 $this->protocol = $version; 45 } 46 public function getStatusCode(): int 47 { 48 return $this->statusCode; 49 } 50 public function getReasonPhrase(): string 51 { 52 return $this->reasonPhrase; 53 } 54 /** 55 * @return static 56 */ 57 public function withStatus($code, $reasonPhrase = ''): ResponseInterface 58 { 59 if (!\is_int($code) && !\is_string($code)) { 60 throw new \InvalidArgumentException('Status code has to be an integer'); 61 } 62 $code = (int) $code; 63 if ($code < 100 || $code > 599) { 64 throw new \InvalidArgumentException(\sprintf('Status code has to be an integer between 100 and 599. A status code of %d was given', $code)); 65 } 66 $new = clone $this; 67 $new->statusCode = $code; 68 if ((null === $reasonPhrase || '' === $reasonPhrase) && isset(self::PHRASES[$new->statusCode])) { 69 $reasonPhrase = self::PHRASES[$new->statusCode]; 70 } 71 $new->reasonPhrase = $reasonPhrase; 72 return $new; 73 } 74 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Sat Jun 13 09:38:55 2026 | Cross-referenced by PHPXref |